I wanted to know if it\'s possible to add HTML tags to JavaScript alert() method, such as:
-
et
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'
);
}
Alert formatting
Result in Firefox:

You get the same look in almost all browsers.