HTML DOM Document writeln()
More examples below.
Description
The writeln()
method writes directly to an open (HTML) document stream.
The writeln()
method is identical to the write() method,
with the addition of writing a newline character (U+000A) after each statement.
Warning
The writeln()
method deletes all existing HTML when used on a loaded document.
The writeln()
method cannot be used in XHTML or XML.
Syntax
Parameters
The output stream.
Multiple arguments are appended to the document in order of occurrence.
Return Value
The Difference Between write() and writeln()
writeln() adds a newline character after each statement. write() does not.
Example
document.write("Have a nice day!");
document.write("<br>");
document.writeln("Hello World!");
document.writeln("Have a nice day!");
Note
It makes no sense to use writeln() in HTML.
It is only useful when writing to text documents (type=".txt").
Newline characters are ignored in HTML.
If you want new lines in HTML, you must use paragraphs or <br>:
Examples
document.write("<br>");
document.write("Have a nice day!");
document.write("<p>Have a nice day!</p>");
Browser Support
document.write
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |