
SweetAlert
A JavaScript library that replaces the plain browser alert with styled popup dialogs.
- Stars
- 22.2k
- Forks
- 2.7k
- Licence
- MIT
- Language
- TypeScript
- Last update
- 3.6 years ago
- Type
- Library
No commits in over a year — check for forks or alternatives before adopting.
What it is
SweetAlert is a JavaScript library that shows popup dialogs on a web page in place of the plain built-in alert box. You call it with a title, text, or an icon, and it displays a styled modal that can also ask for confirmation or text input. Web developers use it to make pop-up messages look nicer and to get the user's answer back as a promise.
- Show a success or error message after a form submission
- Ask 'Are you sure?' before deleting an item and act on the answer
- Prompt the user to type a value and then use it in the page
- Display a message that fetches data from an API after the user confirms
Great for
- Web developers who want nicer alert and confirm popups than the browser default
- Projects that already use npm and modern JavaScript imports
- Sites that need a quick yes/no confirmation before a delete or leave-page action
- Developers who need a simple text input prompt in a modal
Not ideal for
- People who are not writing or editing a website, since it requires code to use
- Projects that need a React-native component model; the README points to a separate package, @sweetalert/with-react, for that
- Teams needing active maintenance guarantees, since the last push in the provided metadata is from April 2023
How to get it
- 1
Install with a package manager
You'll need: Node.js and npm, or another JavaScript package manager
Install SweetAlert from npm
npm install --save sweetalert - 2
Run it
- Install the package with npm install --save sweetalert
- Import it in your code with import swal from 'sweetalert';
- Call swal("Hello world!"); to show your first popup
- Try the examples in the README, such as the confirm dialog with dangerMode
- 3
Get the most out of it
- Use the promise or async/await form to act on the user's choice in confirm dialogs
- Use the content: "input" option to collect a text value from the user
- Pass a custom button object to change the button text or keep the modal open while a fetch runs
- Use the @sweetalert/with-react package if you want to render JSX inside alerts
Downloads
Strengths
- Simple one-line call for common alerts, such as swal("Hello world!")
- Returns the user's choice as a promise, so it works with async/await
- Has a documented theming section and a guides site at sweetalert.js.org
Trade-offs
- The README does not show recent maintenance; last push is 2023-04-15 in the provided metadata
- Upgrading from version 1.x involves breaking changes, according to the README
- Usage details beyond the README are on the external docs site, which this analysis did not review
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| sweetalert (this) | 22.2k | Library | beginner | 3.6 years ago | Web developers who want nicer alert and confirm popups than the browser default |
| sweetalert2 | 18.1k | Library | beginner | 9 days ago | Web developers who want nicer popups than the browser's built-in alert and confirm boxes |
| Semantic-UI | 51k | Library | beginner | 1.9 years ago | Front-end developers who want prebuilt UI components they can restyle with themes |
| ui | 127k | Library | intermediate | 4 days ago | Developers building React or Next.js interfaces who want full control over component code |
| primitives | 19.5k | Library | intermediate | 22 days ago | Developers building a custom design system who want accessible base components |
| shoelace | 13.8k | Library | intermediate | 6 months ago | Developers maintaining an existing site that already uses Shoelace |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.