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
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ met_win_alert.asp
Window alert() Method
More examples below. The alert() method displays an alert box with a message and an OK button.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ html โ€บ html-dom-window-alert-method
HTML DOM Window alert() Method - GeeksforGeeks
In this example the alert() is used to display a message box when the button is double-clicked. The message informs users about GeeksforGeeks. It's a simple way to show notifications or information.
Published ย  July 11, 2025
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ API โ€บ Window โ€บ alert
Window: alert() method - Web APIs | MDN
window.alert() instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_popup.asp
JavaScript Popup Boxes
The window.alert() method can be written without the window prefix. ... A confirm box is often used if you want the user to verify or accept something. When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed.
๐ŸŒ
Quackit
quackit.com โ€บ javascript โ€บ javascript_alert_box.cfm
JavaScript Alert Box
This example, on the other hand, loads automatically as the page is loading. By placing the code by itself (i.e. not within a link/button), this will automatically trigger the alert box as soon as the page is loading. The alert will popup as the browser renders the code. Therefore, if you place the code within the <head> tags, your alert box will popup before the HTML ...
๐ŸŒ
OneCompiler
onecompiler.com โ€บ html โ€บ 3xfmfsrwk
html alert box - HTML - OneCompiler
The editor shows sample boilerplate code when you choose language as HTML.
Find elsewhere
๐ŸŒ
University of Washington
washington.edu โ€บ accesscomputing โ€บ webd2 โ€บ student โ€บ unit5 โ€บ module2 โ€บ lesson1.html
Lesson 1: Using JavaScript to Show an Alert
As mentioned in Beyond HTML, a variable in a programming or scripting language is a symbolic name that represents a value. In our earlier PHP example, we used the variable $thisPage to control certain features in the showTop() function. In PHP, variable names must start with a $, but that isn't the case in JavaScript. Take a look at the following example, which uses a variable named myText to customize the text that's displayed in the alert box...
๐ŸŒ
Uw
projects.accesscomputing.uw.edu โ€บ webd2 โ€บ student โ€บ unit5 โ€บ module2 โ€บ lesson1.html
Lesson 5.2.1: Using JavaScript to Show an Alert
As mentioned in Beyond HTML, a variable in a programming or scripting language is a symbolic name that represents a value. In our earlier PHP example, we used the variable $thisPage to control certain features in the showTop() function. In PHP, variable names must start with a $, but that isn't the case in JavaScript. Take a look at the following example, which uses a variable named myText to customize the text that's displayed in the alert box...
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ tryit.asp
W3Schools Tryit Editor - JavaScript Alert
The W3Schools online code editor allows you to edit code and view the result in your browser
๐ŸŒ
W3Schools
www-db.deis.unibo.it โ€บ courses โ€บ TW โ€บ DOCS โ€บ w3schools โ€บ howto โ€บ howto_js_alert.asp.html
How To Create an Alert Message Box
Well organized and easy to understand Web bulding tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, and XML.
๐ŸŒ
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 - 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. When the button is clicked, then trigger the SweetAlert2 alert box by calling the Swal.fire() function with some desired options such as title, text, icon, and confirm button text. Example: The below example illustrates the implementation to design a custom alert box using SweetAlert2 library.
๐ŸŒ
W3Schools
w3schools.com โ€บ bootstrap โ€บ bootstrap_alerts.asp
Bootstrap Alerts
To close the alert message, add a .alert-dismissible class to the alert container. Then add class="close" and data-dismiss="alert" to a link or a button element (when you click on this the alert box will disappear).
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ html โ€บ how-to-show-javascript-alert-box-in-the-middle-of-the-screen
How to show JavaScript alert box in the middle of the screen? - GeeksforGeeks
July 23, 2025 - Example: The code below shows an alert box in the middle of the screen using CSS and JavaScript. ... <!DOCTYPE html> <html> <head> <title>Centered Alert Box</title> <style> body { display: flex; flex-direction: column; justify-content: center; ...
๐ŸŒ
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 });
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 41136691 โ€บ how-to-design-alert-box-in-html
How to design alert box in HTML - javascript
The javascript alert() is a system message box that will will block your page whilst it displays and will look different on different operating systems. What you are looking for is usually referred to as a dialog box or modal popup, these are constructed using html and javascript to look like the page behind is blocked or greyed out. If you are starting out, you could look at some examples like: https://www.w3schools.com/howto/howto_css_modals.asp These are build from scratch.
๐ŸŒ
TutorialsTeacher
tutorialsteacher.com โ€บ javascript โ€บ display-popup-message-in-javascript
JavaScript Message Boxes: alert(), confirm(), prompt()
alert("This is an alert message box."); // display string message alert('This is a numer: ' + 100); // display result of a concatenation alert(100); // display number alert(Date()); // display current date ...
๐ŸŒ
Penn State
accessibility.psu.edu โ€บ scripts โ€บ alertboxes
Accessibility at Penn State | Alert Boxes
September 15, 2018 - The code for the button is a FORM element with the question embedded in a LABEL tag and a button with the an onClick event triggering the alert box.