SweetAlert2 replaces native alert, confirm, and prompt dialogs in web pages. It adds styling, customization, and WAI-ARIA accessibility without extra dependencies.
Overview
SweetAlert2 is a browser library that substitutes JavaScript built-in popup boxes with styled modal dialogs. It targets responsive layouts, theme options, and accessibility through WAI-ARIA attributes, and ships without requiring other front-end packages.
The API centers on a fire method that accepts titles, text, icons, buttons, timers, and HTML content. Examples in the documentation cover confirmations, dismiss handling, input types, AJAX-driven prompts, RTL languages, toast-style notifications, and positioned dialogs.
Themes include built-in light and dark modes, auto light-or-dark detection, and separate CSS packs for Bootstrap, Material UI, Bulma, and other UI kits. Integrations are documented for React, Vue, Angular, and Laravel among common stacks.
Installation is available through npm, CDN delivery, or classic script tags. Developers import the module in bundled apps or load JS and CSS separately when customizing styles.
Key features
- Modal alerts, confirms, and prompts
- WAI-ARIA accessible markup
- Zero declared runtime dependencies
- Multiple visual themes and CSS packs
- Toast and timed auto-close dialogs
- Custom HTML and button layouts
- RTL language support
- Framework integration guides
Use cases
- Styled confirm before destructive actions
- Success and error feedback modals
- Form input inside a dialog
- Accessible replacements for window.alert