You can use all Unicode characters and the escape characters \n and \t. An example:
document.getElementById("test").onclick = function() {
alert(
'This is an alert with basic formatting\n\n'
+ "\t• list item 1\n"
+ '\t• list item 2\n'
+ '\t• list item 3\n\n'
+ '▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬▬\n\n'
+ 'Simple table\n\n'
+ 'Char\t| Result\n'
+ '\\n\t| line break\n'
+ '\\t\t| tab space'
);
}
<!DOCTYPE html>
<title>Alert formatting</title>
<meta charset=utf-8>
<button id=test>Click</button>
Result in Firefox:

You get the same look in almost all browsers.
Answer from fuxia on Stack OverflowW3Schools
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.
W3Schools
w3schools.com › jsref › met_win_alert.asp
Window alert() Method
It prevents the user from accessing other parts of the page until the alert box is closed. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
HTML Tags in Javascript Alert() method - Stack Overflow
I wanted to know if it's possible to add HTML tags to JavaScript alert() method, such as: etc. Thanks for your help More on stackoverflow.com
how do I call an alert(); to a javascript tag
William Bouknight is having issues with: A task has asked me to write a program inside a script tag that would open a alert(); that said warning!. I attempted the code and the box with ... More on teamtreehouse.com
html - JavaScript (Alert Message) - Stack Overflow
I have written a JavaScript alert message code it displays the alert message first in both codes 1 and 2 before Html content. What should I do to run the HTML content first and then a javascript c... More on stackoverflow.com
where do i put the alert command in JavaScript
That way, the browser knows that the code between the script tags is JavaScript. Outside of these tags, it will think your code is either HTML or regular text. In your example, you put the alert after the script tags (so HTML doesn't know it is part of a script). More on teamtreehouse.com
Videos
12:14
How to Create Custom Alert Box using Javascript Tutorial - YouTube
38:55
Alert Notification using HTML, CSS and Javascript - YouTube
How to Create a Webpage Alert Using JavaScript – Easy JavaScript ...
#8 JavaScript Alert or POPUP | JavaScript Tutorial for Beginners ...
01:18
Onclick Alert Javascript Tutorial For Beginners - YouTube
11:19
JavaScript Tutorial | Create Alert Box & Change HTML Content/S...
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › alert
Window: alert() method - Web APIs | MDN - Mozilla
window.alert() instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog.
University of Washington
washington.edu › accesscomputing › webd2 › student › unit5 › module2 › lesson1.html
Lesson 1: Using JavaScript to Show an Alert
You will start by writing a simple ... text editor. Add the following JavaScript code to the <head> section of your web page: <script> function showAlert() { alert ("Hello world!"); } </script>...
GeeksforGeeks
geeksforgeeks.org › html › html-dom-window-alert-method
HTML DOM Window alert() Method - GeeksforGeeks
... <!DOCTYPE html> <html lang="en"> ... green;"> GeeksforGeeks </h1> <p> For displaying the alert message, double click the "Show Alert Message" button: </p> <button ondblclick="myalert()"> Show Alert Message </button> <script> ...
Published July 11, 2025
Top answer 1 of 6
53
You can use all Unicode characters and the escape characters \n and \t. An example:
document.getElementById("test").onclick = function() {
alert(
'This is an alert with basic formatting\n\n'
+ "\t• list item 1\n"
+ '\t• list item 2\n'
+ '\t• list item 3\n\n'
+ '▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬▬\n\n'
+ 'Simple table\n\n'
+ 'Char\t| Result\n'
+ '\\n\t| line break\n'
+ '\\t\t| tab space'
);
}
<!DOCTYPE html>
<title>Alert formatting</title>
<meta charset=utf-8>
<button id=test>Click</button>
Result in Firefox:

You get the same look in almost all browsers.
2 of 6
26
alert() is a method of the window object that cannot interpret HTML tags
Uw
projects.accesscomputing.uw.edu › webd2 › student › unit5 › module2 › lesson1.html
Lesson 5.2.1: Using JavaScript to Show an Alert
You will start by writing a simple ... text editor. Add the following JavaScript code to the <head> section of your web page: <script> function showAlert() { alert ("Hello world!"); } </script>...
Team Treehouse
teamtreehouse.com › community › how-do-i-call-an-alert-to-a-javascript-tag
how do I call an alert(); to a javascript tag (Example) | Treehouse Community
April 9, 2017 - A task has asked me to write a program inside a script tag that would open a alert(); that said warning!. I attempted the code and the box with the message appeared now it says my script tag no longer works. ... <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JavaScript Basics</title> </head> <body> <script src="scripts.js"></script> <script> alert("Warning!"); </script> </body> </html>
Top answer 1 of 5
3
There is a load event, which will fire AFTER the page is loaded. You can listen to the event:
window.addEventListener('load', function() {
console.log('All assets are loaded');
alert ("This is an alert MSG");
})
2 of 5
0
You can use setTimeout() for this
<html>
<head>
<title>Hello, World !</title>
</head>
<body>
<h1>I am learning JavaScript.</h1>
<div id="Content">
<p>This is a paragraph tag. Here the content of html.</p>
</div>
<script>
setTimeout(()=>{
alert(" This is alert message.")
},2000)
</script>
</body>
</html>
Telerik
telerik.com › blogs › how-to-do-javascript-alerts-without-being-a-jerk
How To Do JavaScript Alerts Without Being A Jerk
May 27, 2021 - Nearly every JavaScript UI framework includes a modal window of some sort. These windows use div overlays to block interaction with the page. There are several reasons why these widgets are better than the browser's native alert... They do not lock the entire browser, only preventing interaction with the viewport ... Many jQuery libraries offer a modal window, including Kendo UI, Telerik HTML5 and JavaScript framework.
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
Team Treehouse
teamtreehouse.com › community › where-do-i-put-the-alert-command-in-javascript
where do i put the alert command in JavaScript (Example) | Treehouse Community
February 16, 2019 - Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today. Start your free trial ... I dont know what i am doing wrong!!! ... <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JavaScript Basics</title> </head> <body> <script src="scripts.js"></script> </script> alert("Warning"); </body> </html>
Stack Overflow
stackoverflow.com › questions › 48105950 › how-do-i-display-a-alert-on-a-website
javascript - How do I display a alert on a website? - Stack Overflow
It looks like you have tagged 'javascript' on this question, so I will show you the most common way to do it completely using javascript. Use the alert() function. The alert function takes one parameter — the text that you want to show.
TutorialsPoint
tutorialspoint.com › javascript-create-an-alert-on-clicking-an-html-button
JavaScript - Create an alert on clicking an HTML button
March 11, 2025 - Display the Alert: The alert function is a built-in JavaScript function that displays a pop-up message with the specified text. var pressedButton = document.getElementsByTagName("button")[0]; pressedButton.addEventListener("click", function (event) { alert("You have pressed the button..........") ...
Quackit
quackit.com › javascript › javascript_alert_box.cfm
JavaScript Alert Box
... If you prefer to have the full ... in the document's <body> tag. ... The most common use for the JavaScript alert is to call it from within a function that does something else....
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Interaction: alert, prompt, confirm
September 8, 2020 - There are other ways to show nicer windows and richer interaction with the visitor, but if “bells and whistles” do not matter much, these methods work just fine. ... Create a web-page that asks for a name and outputs it. ... <!DOCTYPE html> <html> <body> <script> 'use strict'; let name = prompt("What is your name?", ""); alert(name); </script> </body> </html>
Javatpoint
javatpoint.com › javascript-alert
JavaScript alert() - javatpoint
JavaScript alert() with javascript tutorial, introduction, javascript oops, application of javascript, loop, variable, objects, map, typedarray etc.
SheCodes
shecodes.io › athena › 67094-how-to-create-an-alert-in-javascript
[JavaScript] - How to create an alert in JavaScript - | SheCodes
Learn how to create a pop-up alert message in JavaScript using the alert() method.