coderef

Trusted typesBaseline · Newly available

Trusted types allow you to lock down insecure parts of the DOM API and prevent client-side cross-site scripting (XSS) attacks.

Works in the latest version of every major browser, but older devices may not support it yet. Baseline since Feb 24, 2026.

Browser support

DesktopChrome
1–81Not supported
83+Supportedsince May 19, 2020
Current: 155
Edge
12–81Not supported
83+Supportedsince May 21, 2020
Current: 154
Firefox
1–147Not supported
148+Supportedsince Feb 24, 2026
Current: 157
Safari
1–18.6Not supported
26+Supportedsince Sep 15, 2025
Current: 27
MobileChrome Android
18–81Not supported
83+Supportedsince May 19, 2020
Current: 155
Firefox Android
4–147Not supported
148+Supportedsince Feb 24, 2026
Current: 157
Safari iOS
1–18.6Not supported
26+Supportedsince Sep 15, 2025
Current: 27

How to use

Every current browser supports this, but it only became Baseline on Feb 24, 2026. Use it as a progressive enhancement, or keep a fallback if you support older devices.

Example

Full syntax and examples are on MDN: TrustedHTML.

Feature detection

JS · check before using
if ("trustedTypes" in globalThis) {
  // trustedTypes is available
} else {
  // load a polyfill or use a fallback
}

Sub-features

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

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Element.innerHTML.enforces_trusted_types8383148268314826
HTMLScriptElement.innerText.enforces_trusted_types8383148268314826
HTMLScriptElement.src.enforces_trusted_types8383148268314826
HTMLScriptElement.text.enforces_trusted_types8383148268314826
HTMLScriptElement.textContent.enforces_trusted_types8383148268314826
ShadowRoot.innerHTML.enforces_trusted_types8383148268314826
TrustedHTML8383148268314826
TrustedHTML.toJSON9090148269014826
TrustedHTML.toString8383148268314826
TrustedScript8383148268314826
TrustedScript.toJSON9090148269014826
TrustedScript.toString8383148268314826
TrustedScriptURL8383148268314826
TrustedScriptURL.toJSON9090148269014826
TrustedScriptURL.toString8383148268314826
TrustedTypePolicy8383148268314826
TrustedTypePolicy.createHTML8383148268314826
TrustedTypePolicy.createScript8383148268314826
TrustedTypePolicy.createScriptURL8383148268314826
TrustedTypePolicy.name8383148268314826
Show 15 more
Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
TrustedTypePolicyFactory8383148268314826
TrustedTypePolicyFactory.createPolicy8383148268314826
TrustedTypePolicyFactory.defaultPolicy8383148268314826
TrustedTypePolicyFactory.emptyHTML8383148268314826
TrustedTypePolicyFactory.emptyScript8383148268314826
TrustedTypePolicyFactory.getAttributeType8383148268314826
TrustedTypePolicyFactory.getPropertyType8383148268314826
TrustedTypePolicyFactory.isHTML8383148268314826
TrustedTypePolicyFactory.isScript8383148268314826
TrustedTypePolicyFactory.isScriptURL8383148268314826
setInterval.code_param_enforces_trusted_types8383148268314826
setTimeout.code_param_enforces_trusted_types8383148268314826
trustedTypes8383148268314826
http.headers.Content-Security-Policy.require-trusted-types-for8383148268314826
http.headers.Content-Security-Policy.trusted-types8383148268314826