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 Dialogue does a lot of the work for you, working basically as I have described: Link.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#dialog" ).dialog();
  } );
  </script>
</head>
<body>
 
<div id="dialog" title="Basic dialog">
  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
 
 
</body>
</html>

Answer from PCasagrande on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ howto โ€บ howto_js_alert.asp
How To Create an Alert Message Box
<div class="alert"> <span class="closebtn" onclick="this.parentElement.style.display='none';">&times;</span> This is an alert box.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ How-to-create-and-apply-CSS-to-JavaScript-Alert-box
How to create and apply CSS to JavaScript Alert box?
The custom alert box will be created using jQuery and styles will be applied to CSS. You can try to run the following code to learn how to create and apply CSS to alert box โˆ’ ... <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ How-to-design-a-custom-alert-box-using-JavaScript
How to design a custom alert box using JavaScript?
Now will style the button present inside the alert box by providing it color, margin, radius, border, and width. Also align the text to the centre. At last, provide the styling to the text present in the alert box by aligning the text. We can use the below code to create a custom alert box ?
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ css โ€บ how-to-change-the-style-of-alert-box-using-css
How to change the style of alert box using CSS ? - GeeksforGeeks
July 12, 2025 - But the JavaScript alert box is a system object not the subject of CSS. To design the alert box we need jQuery then by using the only CSS we can do that.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ How-I-can-change-the-style-of-alert-box-using-JavaScript
How I can change the style of alert box using JavaScript?
To change the style, use the following custom alert box. Weโ€™re using JavaScript library, jQuery to achive this. ... <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"> </script> <script> function functionAlert(msg, myYes) { var confirmBox = $("#confirm"); confirmBox.find(".message").text(msg); confirmBox.find(".yes").unbind().click(function() { confirmBox.hide(); }); confirmBox.find(".yes").click(myYes); confirmBox.show(); } </script> <style> #confirm { display: none; background-color: #514E61; color: #FFFFFF; border: 1px solid #aaa;
๐ŸŒ
Js
alertbox.js.org
AlertBox - A simple, beautiful, responsive, easy to use, customizable text for JavaScript's Alert Box.
alertbox.render({ alertIcon: 'warning', title: 'Thank You!', message: 'AlertBox Popup Message', btnTitle: 'Ok', border:true });
๐ŸŒ
CodePen
codepen.io โ€บ skazee โ€บ pen โ€บ xVvWdq
Window Alert with CSS Style
var ALERT_TITLE = "Oops!"; var ALERT_BUTTON_TEXT = "Ok"; if(document.getElementById) { window.alert = function(txt) { createCustomAlert(txt); } } function createCustomAlert(txt) { d = document; if(d.getElementById("modalContainer")) return; mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div")); mObj.id = "modalContainer"; mObj.style.height = d.documentElement.scrollHeight + "px"; alertObj = mObj.appendChild(d.createElement("div")); alertObj.id = "alertBox"; if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px"; alertObj.style.left = (d
Find elsewhere
๐ŸŒ
CSS Script
cssscript.com โ€บ home โ€บ alert
Latest Free Alert Dialog Boxes In JavaScript & CSS - CSS Script
DemoDownload ยท Category: Javascript , Notification | January 11, 2025 ... A JavaScript library that creates iOS-style bottom sheets, alert/confirmation/prompt dialogs, toast messages, and notification bars on your website.
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 2838437 โ€บ how-to-style-an-alert-box-in-javascript
How to style an alert box in javascript | Sololearn: Learn to code for FREE!
You can have a look at it: https://stackoverflow.com/questions/7853130/how-to-change-the-style-of-alert-box ... clement ndiok Sweet alert js library is best.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-design-a-custom-alert-box-using-javascript
How to Design a Custom Alert Box using JavaScript ? - GeeksforGeeks
July 23, 2025 - Create the HTML file with the basic structure including a button to trigger the custom alert box. Then import the SweetAlert2 library by adding the appropriate <link> tag in the <head> section of your HTML file for CSS, and <script> tag before the closing <body> tag for JavaScript...
๐ŸŒ
CodePen
codepen.io โ€บ nishanc โ€บ pen โ€บ NWWPdZE
Custom JS Alert
function CustomAlert(){ this.alert = function(message,title){ document.body.innerHTML = document.body.innerHTML + '<div id="dialogoverlay"></div><div id="dialogbox" class="slit-in-vertical"><div><div id="dialogboxhead"></div><div id="dialogboxbody"></div><div id="dialogboxfoot"></div></div></div>'; let dialogoverlay = document.getElementById('dialogoverlay'); let dialogbox = document.getElementById('dialogbox'); let winH = window.innerHeight; dialogoverlay.style.height = winH+"px"; dialogbox.style.top = "100px"; dialogoverlay.style.display = "block"; dialogbox.style.display = "block"; document
๐ŸŒ
Speckyboy
speckyboy.com โ€บ home โ€บ css โ€บ 10 free css & js notification alert code snippets
10 Free CSS & JS Notification Alert Code Snippets for Web Designers
February 5, 2025 - Simply titled formrun.js this uses a pure CSS dialog modal to handle error messages when submitting a login form. The best part is that you can apply this to pretty much any form like checkout pages or user settings pages. Hereโ€™s a fun little alert box created from scratch by developer Luca Moser.
๐ŸŒ
Snap! Forum
forum.snap.berkeley.edu โ€บ advanced topics
How can I make a custom javascript alert() box like the one in the snap website? - Advanced Topics - Snap! Forum
July 31, 2022 - Ik this is offtopic but I'm making a website and I want to make a custom alert box like the one in the snap website ex:
๐ŸŒ
University of Washington
washington.edu โ€บ accesscomputing โ€บ webd2 โ€บ student โ€บ unit5 โ€บ module2 โ€บ lesson1.html
Using JavaScript to Show an Alert
After you have added the button, add a new <style> element to the head section of your page, and add a new style for the button element. Use CSS pseudo-classes (:hover, :focus, and :active) to make the button change its appearance when users hover over it with a mouse or tab to it with keyboard.
Top answer
1 of 1
4

There were two main problems:

  1. You were creating the dialog <div /> but you weren't actually appending it to the document
  2. You were defining alert but you weren't actually calling it anywhere

I've fixed these two things in the below snippet:

function alert(title, content) {
  var alertContent = `
    <div class="modal__overlay verdana">
      <div class="modal__window">
        <div class="modal__titlebar">
          <span class="modal__title">${title}</span>                        
          <button class="modal__close">X</button>                    
        </div>                     
        <div class="modal__content">${content}</div>
      </div>
    </div>`
  var dialogBox = document.createElement("div");
  dialogBox.innerHTML = alertContent;
  document.body.appendChild(dialogBox); // actually append it
}

alert('hello', 'hello world'); // call it here
.verdana {
  font-family: Verdana;
}

.modal__overlay {
  position: fixed;
  width: 100vw;
  height: 100vh;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000000000000000000;
}

.modal__window {
  max-width: 500px;
  background: #ffffff;
  border: 1px solid #ffffff;
  font-size: 16px;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.25);
}

.modal__titlebar {
  height: 40px;
  background: #333333;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal__title {
  margin-left: 15px;
  font-weight: bold;
  color: #eeeeee;
}

.modal__close {
  width: 40px;
  height: 40px;
  outline: none;
  border: none;
  background: transparent;
  color: #eeeeee;
  cursor: pointer;
}

.modal__close:active {
  transform: scale(0.9);
}

.modal__content {
  padding: 15px;
  font-size: 0.9em;
}

Two other things to consider:

  1. You don't need to use string concatenation when using template literals; you can simply embed the expression
  2. Window.alert is a predefined function which you are potentially shadowing with your own function; I'd recommend giving it a different name.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ javascript โ€บ javascript customize alert box
How to Create Customized Alert Box in JavaScript | Delft Stack
February 2, 2024 - ... Get the HTML body element. Get the alert container. Use the removeChild method to remove the alert container from the HTML body element. Finally, create CSS styles to style the custom alert function.