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
Indicates a warning that might need attention. ... <div class="alert"> <span class="closebtn" onclick="this.parentElement.style.display='none';">&times;</span> This is an alert box.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ met_win_alert.asp
Window alert() Method
The alert() method displays an alert box with a message and an OK button. The alert() method is used when you want information to come through to the user.
๐ŸŒ
Bootstrap
getbootstrap.com โ€บ docs โ€บ 5.0 โ€บ components โ€บ alerts
Alerts ยท Bootstrap v5.0
Alerts are available for any length of text, as well as an optional close button. For proper styling, use one of the eight required contextual classes (e.g., .alert-success). For inline dismissal, use the alerts JavaScript plugin.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ html โ€บ html-dom-window-alert-method
HTML DOM Window alert() Method - GeeksforGeeks
The alert() method in HTML and JavaScript is used to display an alert box with a specified message.
Published ย  July 11, 2025
๐ŸŒ
Quackit
quackit.com โ€บ javascript โ€บ javascript_alert_box.cfm
JavaScript Alert Box
Also see the HTML <dialog> tag. The JavaScript alert box is useful for alerting your users to something important. When a JavaScript alert box is triggered, a small box will pop up and display the text that you specify in your JavaScript code.
๐ŸŒ
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
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Bootcamp JS Certificate JS Reference ... An alert box is often used if you want to make sure information comes through to the user.
Find elsewhere
๐ŸŒ
W3Schools
www-db.deis.unibo.it โ€บ courses โ€บ TW โ€บ DOCS โ€บ w3schools โ€บ howto โ€บ howto_js_alert.asp.html
How To Create an Alert Message Box
Indicates a warning that might need attention. <div class="alert"> <span class="closebtn" onclick="this.parentElement.style.display='none';">&times;</span> This is an alert box. </div> If you want the ability to close the alert message, add a <span> element with an onclick attribute that says ...
๐ŸŒ
Js
alertbox.js.org
AlertBox - A simple, beautiful, responsive, easy to use, customizable text for JavaScript's Alert Box.
alertbox.render({ alertIcon: 'info', title: 'Thank You!', message: 'AlertBox Popup Message', btnTitle: 'Ok', border:true });
๐ŸŒ
Bootstrap
getbootstrap.com โ€บ docs โ€บ 4.0 โ€บ components โ€บ alerts
Alerts ยท Bootstrap
Alerts are available for any length of text, as well as an optional dismiss button. For proper styling, use one of the eight required contextual classes (e.g., .alert-success). For inline dismissal, use the alerts jQuery plugin.
๐ŸŒ
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; align-items: center; height: 100vh; margin: 0; } #alert { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); padding: 20px; background-color: #f0f0f0; border: 1px solid #ddd; } .heading { color: green; font-size: 40px; } </style> </head> <body> <h1 class="heading"> GeeksForGeeks </h1> <h4> alert box in the middle Using
๐ŸŒ
TutorialsTeacher
tutorialsteacher.com โ€บ javascript โ€บ display-popup-message-in-javascript
JavaScript Message Boxes: alert(), confirm(), prompt()
JavaScript provides built-in global functions to display popup message boxes for different purposes. alert(message): Display a popup box with the specified message with the OK button.
๐ŸŒ
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
๐ŸŒ
Uw
projects.accesscomputing.uw.edu โ€บ webd2 โ€บ student โ€บ unit5 โ€บ module2 โ€บ lesson1.html
Lesson 5.2.1: Using JavaScript to Show an Alert
Most programming or scripting languages ... useful function that's native to JavaScript is the alert() function. This function will display text in a dialog box that pops up on the screen....
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 41136691 โ€บ how-to-design-alert-box-in-html
How to design alert box in HTML - javascript
Wow 2016-12-14T07:10:34.11Z+00:00 ... 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.
๐ŸŒ
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.
๐ŸŒ
OneCompiler
onecompiler.com โ€บ html โ€บ 3xfmfsrwk
html alert box - HTML - OneCompiler
The text present between start and end tag is called HTML element content. Anything can be a tagname but it's preferred to put the meaningful title to the content present as tag name. Do not forget the end tag. Elements with no content are called empty elements. Elements can have attributes which provides additional information about the element.