HTML Tags in Javascript Alert() method

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:

screenshot Firefox

You get the same look in almost all browsers.

Leave a Comment