document.writeln() method does not write in a new line

Last updated:4th Nov 2021

writeln(): write a string of text and add a newline character after each statement.

but when you write string inside multiple writeln() method, you observe that writeln() doesn't write to a new line.

This is because all whitespace is converted into a single space when rendering into HTML that why your newline does not work inside your HTML file.

if you want your writeln() method write to a new line, for that write code inside pre tag, for example

<html>
<body>
  <p>kept writeln inside pre tag</p>
    <pre><script>
	  document.writeln("Hello everyone1");
	  document.writeln("Hello everyone2");
   </script> </pre>
</body>
</html>
Run now