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: 155Edge
12+Supportedsince Jul 29, 2015
Current: 154Firefox
1–68Not supported
69+Supportedsince Sep 3, 2019
Current: 157Safari
1–10.1Not supported
11+Supportedsince Sep 19, 2017
Current: 27MobileChrome Android
18–44Not supported
45+Supportedsince Sep 1, 2015
Current: 155Firefox Android
4–68Not supported
79+Supportedsince Jul 28, 2020
Current: 157Safari iOS
1–10.3Not supported
11+Supportedsince Sep 19, 2017
Current: 27How 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-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| Document.close | 45 | 12 | 69 | 11 | 45 | 79 | 11 |
| Document.open | 45 | 12 | 69 | 11 | 45 | 79 | 11 |
| Document.write | 45 | 12 | 69 | 11 | 45 | 79 | 11 |
| Document.write.enforces_trusted_types | 86 | 86 | 148 | 26 | 86 | 148 | 26 |
| Document.writeln | 45 | 12 | 69 | 11 | 45 | 79 | 11 |
| Document.writeln.enforces_trusted_types | 86 | 86 | 148 | 26 | 86 | 148 | 26 |