What is SweetAlert?

SweetAlert is a JavaScript library that allows developers to create beautiful and customizable alert dialogs. It's a great alternative to the standard browser alert and confirm dialogs which can be bland and unattractive.

How to Use SweetAlert

Using SweetAlert in your project is straightforward. You can either download the library from the SweetAlert website or use a CDN link to include it in your project.

 <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11">

Once you have included the SweetAlert library, you can create your own alert dialogs with a few lines of code.

Creating an Alert Dialog

To create an alert dialog with SweetAlert, you can simply call the sweetalert() function, passing in an object with the alert options:

  title: "Hello!",
  text: "Welcome to my blog!",
  icon: "success",
  button: "OK",

This will create an alert dialog with the text "Hello!" and a message "Welcome to my blog!". The dialog will have a green success icon and a single button labelled "OK".

Customizing SweetAlert Dialogs

SweetAlert allows you to customize your alert dialogs to fit your project's design. You can change the dialog's title, text, icon, buttons, and more.

Here are some of the customization options for SweetAlert:

  • title: The title of the dialog.
  • text: The message displayed in the dialog.
  • icon: The icon displayed in the dialog. SweetAlert comes with several built-in icons, including success, error, warning, and info. You can also use your own custom icons.
  • buttons: The buttons displayed in the dialog. You can customize the button text, color, and event handlers.
  • timer: The amount of time the dialog will remain open before automatically closing.
  • showCancelButton: Whether to show a cancel button in the dialog.
  • confirmButtonText: The text displayed on the confirm button.
  • cancelButtonText: The text displayed on the cancel button.
  • confirmButtonColor: The color of the confirm button.
  • cancelButtonColor: The color of the cancel button.

With these customization options, you can create alert dialogs that match your project's design and user experience.


SweetAlert is a powerful and easy-to-use JavaScript library that allows developers to create beautiful and customized alert dialogs. By using SweetAlert, you can enhance your project's user experience and improve its overall design.

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]