SweetAlert2

A beautiful, responsive, customizable, accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies.


See SweetAlert2 in action ↗

Build Status: Linux Build Status: Windows Coverage Status Version semantic-release badge jsdelivr PayPal Donate

--- :point_right: **Upgrading from v7.x to v8.x?** [Read the release notes!](https://github.com/sweetalert2/sweetalert2/releases/tag/v8.0.0)
If you're upgrading from v6.x, please [upgrade from v6 to v7](https://github.com/sweetalert2/sweetalert2/releases/tag/v7.0.0) first! :point_right: **Migrating from [SweetAlert](https://github.com/t4t5/sweetalert)?** [SweetAlert 1.x to SweetAlert2 migration guide](https://github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2) --- Installation ------------ ```bash npm install --save sweetalert2 ``` Or download from CDN: [jsdelivr.com/package/npm/sweetalert2](https://www.jsdelivr.com/package/npm/sweetalert2) Usage ----- ```html ``` You can also include the stylesheet separately if desired: ```html ``` Or: ```js // ES6 Modules or TypeScript import Swal from 'sweetalert2.js' // CommonJS const Swal = require('sweetalert2') ``` It's possible to import JS and CSS separately, e.g. if you need to customize styles: ```js import Swal from 'sweetalert2/dist/sweetalert2.js' import 'sweetalert2/src/sweetalert2.scss' ``` Please note that [TypeScript is well-supported](https://github.com/sweetalert2/sweetalert2/blob/master/sweetalert2.d.ts), so you don't have to install a third-party declaration file. Examples -------- The most basic message: ```js Swal.fire('Hello world!') ``` A message signaling an error: ```js Swal.fire('Oops...', 'Something went wrong!', 'error') ``` Handling the result of SweetAlert2 modal: ```js Swal.fire({ title: 'Are you sure?', text: 'You will not be able to recover this imaginary file!', type: 'warning', showCancelButton: true, confirmButtonText: 'Yes, delete it!', cancelButtonText: 'No, keep it' }).then((result) => { if (result.value) { Swal.fire( 'Deleted!', 'Your imaginary file has been deleted.', 'success' ) // For more information about handling dismissals please visit // https://sweetalert2.github.io/#handling-dismissals } else if (result.dismiss === Swal.DismissReason.cancel) { Swal.fire( 'Cancelled', 'Your imaginary file is safe :)', 'error' ) } }) ``` ## [Go here to see the docs and more examples ↗](https://sweetalert2.github.io/) Browser compatibility --------------------- IE11* | Edge | Chrome | Firefox | Safari | Opera | UC Browser* -------|------|--------|---------|--------|-------|------------- :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | \* ES6 Promise polyfill should be included, see [usage example](#usage). Note that SweetAlert2 **does not** and **will not** provide support or functionality of any kind on IE10 and lower. Related projects ------------------------- - [ngx-sweetalert2](https://github.com/sweetalert2/ngx-sweetalert2) - Angular 4+ integration - [sweetalert2-react-content](https://github.com/sweetalert2/sweetalert2-react-content) - React integration - [sweetalert2-webpack-demo](https://github.com/sweetalert2/sweetalert2-webpack-demo) - webpack demo - [sweetalert2-parcel-demo](https://github.com/sweetalert2/sweetalert2-parcel-demo) - overriding SCSS variables demo Related community projects ------------------------- - [avil13/vue-sweetalert2](https://github.com/avil13/vue-sweetalert2) - Vue.js wrapper - [softon/sweetalert](https://github.com/softon/sweetalert) - Laravel 5 Package Collaborators ------------- [![](https://avatars3.githubusercontent.com/u/3198597?v=4&s=80)](https://github.com/zenflow) | [![](https://avatars1.githubusercontent.com/u/1343250?v=4&s=80)](https://github.com/toverux) | [![](https://avatars3.githubusercontent.com/u/9093699?v=4&s=80)](https://github.com/acupajoe) | [![](https://avatars1.githubusercontent.com/u/5918348?v=4&s=80)](https://github.com/samturrell) | [![](https://avatars2.githubusercontent.com/u/4542461?v=4&s=80)](https://github.com/birjolaxew) | [![](https://avatars3.githubusercontent.com/u/17089396?v=4&s=80)](https://github.com/gverni) -|-|-|-|-|- [@zenflow](https://github.com/zenflow) | [@toverux](https://github.com/toverux) | [@acupajoe](https://github.com/acupajoe) | [@samturrell](https://github.com/samturrell) | [@birjolaxew](https://github.com/birjolaxew) | [@gverni](https://github.com/gverni) Contributing ------------ If you would like to contribute enhancements or fixes, please do the following: 1. Fork the `sweetalert2` repository and clone it locally. 2. Make sure you have [npm](https://www.npmjs.com/) or [yarn](https://yarnpkg.com/) installed. 3. When in the SweetAlert2 directory, run `npm install` or `yarn install` to install dependencies. 4. To begin active development, run `npm start` or `yarn start`. This does several things for you: - Lints your code - Builds the `dist` folder - Serves sandbox.html @ http://localhost:8080/ (browser-sync ui: http://localhost:8081/) - Serves unit tests @ http://localhost:3000 - Re-lints, re-builds, re-loads and re-tests as necessary when files change Backers ------- [![](https://avatars0.githubusercontent.com/u/5826089?v=4&s=80)](https://sheetjs.com/) | [![](https://avatars2.githubusercontent.com/u/12075795?v=4&s=80)](https://www.unique-p.ch) -|- [SheetJS LLC](https://sheetjs.com/) | [Unique-P GmbH](https://www.unique-p.ch) Donations --------- Has SweetAlert2 helped you create an amazing application? You can show your support by making a donation: - [Donate via PayPal](https://www.paypal.me/limonte/5eur) ### [Hall of Donators :trophy:](DONATIONS.md)