How do I create a new line in Javascript?

Use the \n for a newline character.


You can also have more than one:

document.write("\n\n\n"); // 3 new lines!  My oh my!

However, if this is rendering to HTML, you will want to use the HTML tag for a newline:


The string Hello\n\nTest in your source will look like this:



The string Hello<br><br>Test will look like this in HTML source:


The HTML one will render as line breaks for the person viewing the page, the \n just drops the text to the next line in the source (if it’s on an HTML page).

Leave a Comment