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 OverflowYou 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.
alert() is a method of the window object that cannot interpret HTML tags
How do you change JavaScript alert title?
you can't. modern browsers will not allow you to change the alert for security reasons. if you need to set it for some reason, use a modal or some other way of letting the user know.
More on reddit.comhow do I call an alert(); to a javascript tag
Html tags in alert box? - JavaScript - SitePoint Forums | Web Development & Design Community
Who else thinks that javascript alert() is an annoying, lazy, and ugly way to notify me of something on your site.
Videos
Instead of “this page says” I would like to change the text to something else.
you can't. modern browsers will not allow you to change the alert for security reasons. if you need to set it for some reason, use a modal or some other way of letting the user know.
Welcome to r/HTML. When asking a question, please ensure that you list what you've tried, and provide links to example code (e.g. JSFiddle/JSBin). If you're asking for help with an error, please include the full error message and any context around it. You're unlikely to get any meaningful responses if you do not provide enough information for other users to help.
Your submission should contain the answers to the following questions, at a minimum:
-
What is it you're trying to do?
-
How far have you got?
-
What are you stuck on?
-
What have you already tried?
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.