Documentation and live examples v2.0.0
quick-alert
Alerts and toasts for Angular, React, Vue, and plain JavaScript. Try an example, then copy the code beside it.
Download & install
Install the package in any JavaScript project. It has no framework runtime dependency.
Terminal
npm install quick-alert
Usage
Import the same API in every framework, then call fire() from a browser event.
JavaScript / TypeScript
import { quickAlert } from 'quick-alert';
const result = await quickAlert.fire({
title: 'Saved',
message: 'Your changes are ready.',
type: 'success',
buttons: 'ok'
});
console.log(result.action, result.dismissedBy);
On the server, importing the package is safe. Open alerts from a browser event or mounted component.
Examples
Each example opens the actual alert. The code on the right uses the same public API.
Last resultWaiting for an alert action
Success modal
Confirm and cancel actions with a promise result.
Example code
const result = await quickAlert.fire({
title: 'Payment received',
subtitle: 'Success modal',
message: 'The customer has paid and the receipt is ready.',
type: 'success',
toast: false,
buttons: 'confirm-cancel',
confirmButtonText: 'View receipt',
cancelButtonText: 'Later',
showCloseButton: true
});
Toast with progress
A positioned toast with close button and progress bar.
Example code
quickAlert.fire({
title: 'Toast notification',
message: 'This toast closes by itself and shows a progress bar.',
type: 'info',
toast: true,
position: 'top-right',
showCloseButton: true,
showProgressBar: true
});
Warning actions
Confirm, deny, and cancel buttons for destructive flows.
Example code
const result = await quickAlert.fire({
title: 'Delete API key?',
subtitle: 'This cannot be undone',
message: 'Deny and cancel buttons make destructive confirmation flows clear.',
type: 'warning',
toast: false,
buttons: 'confirm-deny-cancel',
confirmButtonText: 'Review',
denyButtonText: 'Delete key',
cancelButtonText: 'Cancel',
showCloseButton: true
});
Toast position
Move toast notifications to any supported screen position.
Example code
quickAlert.fire({
title: 'Bottom-right toast',
message: 'Position can be changed per alert.',
type: 'success',
toast: true,
position: 'bottom-right',
timeout: 3500,
showProgressBar: true,
showCloseButton: true
});
Button presets
Use one option for common action layouts.
Example code
const result = await quickAlert.fire({
title: 'Delete item?',
type: 'warning',
buttons: 'confirm-cancel',
confirmButtonText: 'Delete',
cancelButtonText: 'Keep item',
showCloseButton: true
});
Theme and ARIA labels
Use themes, variants, button classes, and accessible labels together.
Example code
quickAlert.fire({
title: '',
message: 'Theme, button variants, custom classes, and ARIA labels can be set per alert.',
type: 'question',
theme: 'dark',
ariaLabel: 'Accessible themed alert',
buttons: 'confirm-cancel',
buttonVariant: 'outline',
confirmButtonVariant: 'solid',
confirmAriaLabel: 'Confirm themed alert',
closeAriaLabel: 'Close themed alert',
showCloseButton: true
});
Slot customClass
Style popup, overlay, icon, text, buttons, close button, and progress.
Example code
quickAlert.fire({
title: 'Slot customClass',
subtitle: 'Every visible slot can be styled',
message: 'Pass classes for every alert slot.',
type: 'warning',
buttons: 'confirm-deny-cancel',
showCloseButton: true,
customClass: {
popup: 'qa-demo-popup',
overlay: 'qa-demo-overlay',
confirmButton: 'qa-demo-confirm',
progressBar: 'qa-demo-progress-bar'
}
});
Queue modals
Open two modals and quick-alert keeps only one visible at a time.
Example code
quickAlert.fire({
id: 'queue-first',
title: 'First queued modal',
toast: false
});
quickAlert.fire({
id: 'queue-second',
title: 'Second queued modal',
toast: false
});
Stack toasts
Multiple toasts in the same position stack without overlapping.
Example code
quickAlert.fire({
id: 'stack-one',
title: 'Stacked toast one',
toast: true,
position: 'top-right'
});
quickAlert.fire({
id: 'stack-two',
title: 'Stacked toast two',
toast: true,
position: 'top-right'
});
Async confirm
Keep the modal open with a loading state while server work runs.
Example code
await quickAlert.fire({
title: 'Verify on server',
message: 'The confirm button enters loading state while preConfirm resolves.',
type: 'warning',
toast: false,
buttons: 'confirm-cancel',
confirmButtonText: 'Verify',
preConfirm: () => new Promise(resolve => setTimeout(resolve, 900))
});
Pauseable timer
Pause timeout and progress while the toast is hovered or focused.
Example code
quickAlert.fire({
id: 'pausing-timer',
title: 'Pauseable timer',
toast: true,
timeout: 5000,
pauseOnHover: true,
pauseOnFocus: true,
onTimerChange: (seconds, id) => console.log(id, seconds)
});
Safe custom content
Render safe DOM nodes without adding unsafe HTML parsing.
Example code
quickAlert.fire({
title: 'Safe custom content',
message: 'Fallback text is ignored when content is provided.',
type: 'info',
content: ({ document }) => {
const list = document.createElement('ul');
list.append('DOM node content', 'No innerHTML');
return list;
}
});
Lifecycle callbacks
Use lifecycle callbacks for analytics and event logs.
Example code
quickAlert.fire({
title: 'Lifecycle callbacks',
buttons: 'confirm-cancel',
onOpen: ({ id }) => console.log('open', id),
onConfirm: (result) => console.log('confirm', result.id),
onCancel: (result) => console.log('cancel', result.id),
onClose: (result) => console.log('close', result.dismissedBy),
onTimeout: (result) => console.log('timeout', result.id)
});
Auto theme
Resolve default or dark styling from the user system preference.
Example code
quickAlert.fire({
title: 'Auto theme',
message: 'theme: auto resolves when the alert opens.',
type: 'success',
theme: 'auto',
ariaLabel: 'Auto theme alert'
});
Global defaults
Configure shared defaults, then reset them when needed.
Example code
quickAlert.configure({
type: 'info',
toast: true,
position: 'top-right',
timeout: 3500,
showProgressBar: true
});
quickAlert.fire({ id: 'docs-toast', title: 'Configured default' });
quickAlert.resetConfig();
Scoped defaults
Create isolated alert instances so defaults do not leak across app areas.
Example code
import { createQuickAlert } from 'quick-alert';
const billingAlert = createQuickAlert({
type: 'question',
position: 'center',
toast: false,
buttons: 'ok'
});
await billingAlert.fire({
title: 'Scoped defaults',
message: 'Only this alert instance receives these defaults.'
});
Close by API
Close one tracked alert by id, or clean up every active alert.
Example code
quickAlert.close('docs-toast');
quickAlert.closeAll();
Integrations
One root import works across frameworks. Use the call in a client event handler; no provider or plugin registration is required.
Angular
Angular
import { quickAlert } from 'quick-alert';
await quickAlert.fire({
title: 'Saved',
message: 'Angular uses the same API.',
type: 'success'
});
React
React
import { quickAlert } from 'quick-alert';
<button onClick={() => quickAlert.fire({
title: 'Saved',
type: 'success'
})}>
Save
</button>
Vue
Vue
<script setup lang="ts">
import { quickAlert } from 'quick-alert';
function save() {
quickAlert.fire({ title: 'Saved', type: 'success' });
}
</script>
Plain JavaScript
Plain JavaScript
import { quickAlert } from 'quick-alert';
document.querySelector('#save').addEventListener('click', () => {
quickAlert.fire({ title: 'Saved', type: 'success' });
});
Next.js
Next.js
'use client';
import { quickAlert } from 'quick-alert';
export function SaveButton() {
return (
<button onClick={() => quickAlert.fire({
title: 'Saved from Next.js',
theme: 'auto'
})}>
Save
</button>
);
}
Nuxt
Nuxt
<script setup lang="ts">
import { quickAlert } from 'quick-alert';
const notify = () => {
quickAlert.fire({
title: 'Saved from Nuxt',
toast: true,
theme: 'auto'
});
};
</script>
SSR
SSR
import { quickAlert } from 'quick-alert';
// Safe during SSR: no document access happens until browser render.
await quickAlert.fire({ title: 'Browser-only UI' });
Themes
Select a built-in preset with theme. The auto preset follows the user's color scheme when the alert opens.
defaultAlert preview
default
Theme code
quickAlert.fire({
title: 'default theme',
theme: 'default',
buttons: 'confirm-cancel'
});
darkAlert preview
dark
Theme code
quickAlert.fire({
title: 'dark theme',
theme: 'dark',
buttons: 'confirm-cancel'
});
autoAlert preview
auto
Theme code
quickAlert.fire({
title: 'auto theme',
theme: 'auto',
buttons: 'confirm-cancel'
});
successAlert preview
success
Theme code
quickAlert.fire({
title: 'success theme',
theme: 'success',
buttons: 'confirm-cancel'
});
minimalAlert preview
minimal
Theme code
quickAlert.fire({
title: 'minimal theme',
theme: 'minimal',
buttons: 'confirm-cancel'
});
glassAlert preview
glass
Theme code
quickAlert.fire({
title: 'glass theme',
theme: 'glass',
buttons: 'confirm-cancel'
});
materialAlert preview
material
Theme code
quickAlert.fire({
title: 'material theme',
theme: 'material',
buttons: 'confirm-cancel'
});
bootstrapAlert preview
bootstrap
Theme code
quickAlert.fire({
title: 'bootstrap theme',
theme: 'bootstrap',
buttons: 'confirm-cancel'
});
Configuration parameters
Pass an options object to quickAlert.fire(). Global defaults can be set with configure(); use createQuickAlert() for isolated defaults.
Options in action
Try the smaller options individually, then copy the option name from the reference table above.
Positions
Button layouts
Transitions and styling
Flows and timing
Handling dismissals
The dismissedBy field tells you how an alert ended, including Escape, timeout, and API close.
Icons
The five alert types use inline SVG icons. Set showIcon: false when an icon is not needed.
✓successIcon code
quickAlert.fire({
title: 'success alert',
type: 'success',
buttons: 'ok'
});
×errorIcon code
quickAlert.fire({
title: 'error alert',
type: 'error',
buttons: 'ok'
});
!warningIcon code
quickAlert.fire({
title: 'warning alert',
type: 'warning',
buttons: 'ok'
});
iinfoIcon code
quickAlert.fire({
title: 'info alert',
type: 'info',
buttons: 'ok'
});
?questionIcon code
quickAlert.fire({
title: 'question alert',
type: 'question',
buttons: 'ok'
});
Methods
Controller methods
quickAlert.configure({ theme: 'minimal' });
const billingAlert = createQuickAlert({
type: 'info',
position: 'top-right'
});
await billingAlert.fire({ title: 'Invoice sent', toast: true });
quickAlert.close('alert-id');
quickAlert.closeAll();
quickAlert.resetConfig();