Document.parseHTMLUnsafe(input) is a static method that parses HTML into a newDocument. By default it does not sanitize — every entity in the input can be injected (MDN). Optional options.sanitizer can filter content.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call Document.parseHTMLUnsafe. Start with this line.
JavaScript
Document.parseHTMLUnsafe(input, options?)
Call
What it does
Document.parseHTMLUnsafe(input, options?)
Primary signature.
Document.parseHTMLUnsafe(...)
Call with the arguments your case needs.
Built into the browser. Call Document.parseHTMLUnsafe(...) on the Document constructor — no import required.
Library declarations
JavaScript
Document.parseHTMLUnsafe(input, options?)
Parameters
Parameter
Description
input
Required. HTML string or TrustedHTML
options.sanitizer
Optional. Sanitizer, config, or "default"; omit = no filter
Return Value
Return Value
Description
*
New Document
JavaScript Examples
Example 1 — Parse Trusted HTML
Create a new Document from a small trusted string.
Hello
text/html
(or "unsupported" on older engines)
How It Works
Detect the static method. Call Document.parseHTMLUnsafe, not on an instance.
Pass trusted markup only. This demo string is hard-coded, not user input.
Read the new Document.body.textContent shows the paragraph text.
Check contentType. MDN: result is text/html.
Example 2 — Script Nodes Are Not Stripped by Default
Literacy check: without a sanitizer, a <script> element remains in the Document.
JavaScript
if (typeof Document.parseHTMLUnsafe !== "function") {
console.log("unsupported");
} else {
const html = "
Hi
/* demo */";
const doc = Document.parseHTMLUnsafe(html);
console.log(!!doc.querySelector("script")); // true
// Do not eval or append this into a live page from untrusted input
}
parseHTML
Hello
(or parseHTMLUnsafe / unsupported depending on browser)
How It Works
Branch on trust. Untrusted → try parseHTML first (MDN).
Fall back to Unsafe. Only when the safe API is missing or input is trusted.
Return which path ran. Makes demos and debugging clear.
Production tip. Pair Unsafe with TrustedHTML or an explicit sanitizer when you must use it.
Compatibility
Browser Support
Document.parseHTMLUnsafe() is Baseline Newly available on MDN (across latest browsers since September 2025). Feature-detect on older engines. See the MDN parseHTMLUnsafe() reference.
✓ Baseline Newly available · 2025
Document.parseHTMLUnsafe()
Parse HTML into a Document without required sanitization. Prefer parseHTML() for untrusted content.
BaselineNewly available 2025
Google Chrome124+
Yes
Microsoft Edge124+
Yes
Mozilla Firefox128+
Yes
Apple Safari26+
Yes
Opera110+
Yes
Internet ExplorerNot supported
No
parseHTMLUnsafe()Modern browsers
Bottom line: Chrome/Edge 124+, Firefox 128+, Safari 26+. Always feature-detect. Prefer parseHTML() or TrustedHTML for security.
Frequently Asked Questions
It is a static method that parses HTML into a new Document. Unlike parseHTML(), it does not sanitize by default — all HTML entities in the input are injected unless you pass a sanitizer (MDN).
No. MDN marks Document.parseHTMLUnsafe() as Baseline 2025 Newly available (since September 2025). It is not Deprecated, Experimental, or Non-standard.
MDN: almost always, on browsers where parseHTML() is supported, because it always removes XSS-unsafe HTML entities. Use parseHTMLUnsafe() only for trusted HTML, TrustedHTML workflows, or when you pass an explicit sanitizer.
MDN: content type "text/html", character set UTF-8, and URL "about:blank" — same shape as parseHTML().
No by default. MDN warns it is an injection sink and a possible XSS vector. Prefer TrustedHTML with Trusted Types CSP, or pass sanitizer: "default" / a custom Sanitizer.
Optional Sanitizer, SanitizerConfig, or the string "default" (XSS-safe default config). If omitted, no sanitizer runs and all HTML is injected (MDN).