how to add new line in string JavaScript
Last updated:4th Nov 2021
In this tutorial, you will learn how you can add a new line in the console and in DOM.
Add a new line in the console output
if you want to add a new line while printing any string, for that you need to add \n symbol, \n stand for new Line.
console.log("hello everyone,\n i have added new line in String");
The output will be:
hello everyone, i have added new line in String
Add new line in DOM output
when you want to add a new line inside a document.write()
, you need to just add
tag inside a string.
Example
<script>
document.write("Hello everyone!<br/>string for new line");
</script>
<script>
document.write("Hello everyone!<br/>string for new line");
</script>
The output will be:
Hello everyone! string for new line