coderef

document.write()Limited availability

The document.open(), document.write(), document.writeln(), and document.close() methods write content to a document, possibly while that document is still loading.

Not yet supported in all major browsers — check the table and provide a fallback.

Discouraged: The dynamic markup insertion API, which includes document.write(), has "very idiosyncratic behavior" which can be difficult to debug. Use instead: DOM

Browser support

DesktopChrome
1–44Not supported
45+Supportedsince Sep 1, 2015
Current: 155
Edge
12+Supportedsince Jul 29, 2015
Current: 154
Firefox
1–68Not supported
69+Supportedsince Sep 3, 2019
Current: 157
Safari
1–10.1Not supported
11+Supportedsince Sep 19, 2017
Current: 27
MobileChrome Android
18–44Not supported
45+Supportedsince Sep 1, 2015
Current: 155
Firefox Android
4–68Not supported
79+Supportedsince Jul 28, 2020
Current: 157
Safari iOS
1–10.3Not supported
11+Supportedsince Sep 19, 2017
Current: 27

How to use

Support is still inconsistent across browsers. Use feature detection and test carefully.

Example

Full syntax and examples are on MDN: close.

Feature detection

JS · check before using
if ("Document" in globalThis && "write" in Document.prototype) {
  // Document.write is available
}

Sub-features

Support for each part of the feature (6). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Document.close45126911457911
Document.open45126911457911
Document.write45126911457911
Document.write.enforces_trusted_types8686148268614826
Document.writeln45126911457911
Document.writeln.enforces_trusted_types8686148268614826