HTML DOM Document writeln()

Example

document.writeln("Hello World!");
document.writeln("Have a nice day!");
Try it Yourself »

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

document.writeln(exp1, exp2, ..., expN)

Parameters

Parameter Description
exp1,... Optional.
The output stream.
Multiple arguments are appended to the document in order of occurrence.

Return Value

NONE

The Difference Between write() and writeln()

writeln() adds a newline character after each statement. write() does not.

Example

document.write("Hello World!");
document.write("Have a nice day!");
document.write("<br>");
document.writeln("Hello World!");
document.writeln("Have a nice day!");
Try it Yourself »

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("Hello World!");
document.write("<br>");
document.write("Have a nice day!");
Try it Yourself »
document.write("<p>Hello World!</p>");
document.write("<p>Have a nice day!</p>");
Try it Yourself »

Browser Support

document.write is supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.