how to change the style of alert box

  1. Home
  2. javascript
  3. how to change the style of alert box

I need to change the style of the “OK” Button in an alert box.

    <script type="text/javascript">
        function show_alert() {
            alert("Hello! I am an alert box!");
    <input type="button" onclick="show_alert()" value="Show alert box" />

First answer

The alert box is a system object, and not subject to CSS. To do this style of thing you would need to create an HTML element and mimic the alert() functionality. The jQuery UI Modal box does a lot of the work for you, working basically as I have described: Link.

Second answer

I use SweetAlert, It’s Awesome, You will get lots of customization option as well as all callbacks


swal("Here's a message!", "It's pretty, isn't it?");

enter image description here

Third answer

Not possible. If you want to customize the dialog’s visual appearance, you need to use a JS-based solution like jQuery.UI dialog.

Spread the love

Related articles

Comments are closed.