Install and get first example SweetAlert

Installation

By NPM/Yarn

NPM combined with a tool like Browserify or Webpack is the recommended method of installing SweetAlert.

 

npm install sweetalert --save

 

Then, simply import it into your application:

 

import swal from 'sweetalert';

 

By CDN

You can also find SweetAlert on unpkg and jsDelivr and use the global swal variable.

 

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

 

Example: Show an alert Hello world

 

<!DOCTYPE html>

<html>

    <body>

        <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

        <p>Example Hello world</p>

 

        <button onclick="run()">Run</button>

 

        <script>

            function run() {

                swal("Hello world!");

            }

        </script>

 

    </body>

</html>

 

Result :