Javascript line break in HTML | br Tag | Alert box “\n”

Break a line in JavaScript can do by using a “br” tag. If you have 2 or more a string then add br enclosed between 2 brackets < > enclosed in double quotation marks, and preceded and followed by the + sign:

USE JS to insert a line break into HTML?

The example of concatenated 2 strings, display in one <p> tag. To break line using a br tag.

Output: EyeHunts
Next Line

Js break line in Alert box

In the alert box, you can use “\n”, to break the sentence into a new line.


Js break line in Alert box

If you want a linebreak in actual javascript, use the \n escape sequence.

Do comment if you knew another way to break the sentence in a new line using JavaScript code or you have any doubts.

Note: The All JS Examples codes are tested on Safari browser (Version 12.0.2) and Chrome.
OS: macOS 10.14 Mojave
Code: HTML 5 Version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.