coderef

Custom highlightsBaseline · Newly available

Custom highlights style arbitrary text ranges, without adding extra elements to the DOM.

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

Browser support

DesktopChrome
1–104Not supported
105+Supportedsince Sep 2, 2022
Current: 155
Edge
12–104Not supported
105+Supportedsince Sep 1, 2022
Current: 154
Firefox
1–148Not supported
149+Supportedsince Mar 24, 2026
Current: 157
Safari
1–17.1Not supported
17.2+Supportedsince Dec 11, 2023
Current: 27
MobileChrome Android
18–104Not supported
105+Supportedsince Sep 2, 2022
Current: 155
Firefox Android
4–148Not supported
149+Supportedsince Mar 24, 2026
Current: 157
Safari iOS
1–17.1Not supported
17.2+Supportedsince Dec 11, 2023
Current: 27

How to use

Every current browser supports this, but it only became Baseline on Mar 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: highlights static.

Feature detection

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

Sub-features

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

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
CSS.highlights_static10510514017.210514017.2
Highlight10510514017.210514017.2
Highlight.@@iterator10510514017.210514017.2
Highlight.Highlight10510514017.210514017.2
Highlight.add10510514017.210514017.2
Highlight.clear10510514017.210514017.2
Highlight.delete10510514017.210514017.2
Highlight.entries10510514017.210514017.2
Highlight.forEach10510514017.210514017.2
Highlight.has10510514017.210514017.2
Highlight.keys10510514017.210514017.2
Highlight.priority10510514017.210514017.2
Highlight.size10510514017.210514017.2
Highlight.type10510514017.210514017.2
Highlight.values10510514017.210514017.2
HighlightRegistry10510514017.210514017.2
HighlightRegistry.@@iterator10510514017.210514017.2
HighlightRegistry.clear10510514017.210514017.2
HighlightRegistry.delete10510514017.210514017.2
HighlightRegistry.entries10510514017.210514017.2
Show 8 more
Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
HighlightRegistry.forEach10510514017.210514017.2
HighlightRegistry.get10510514017.210514017.2
HighlightRegistry.has10510514017.210514017.2
HighlightRegistry.keys10510514017.210514017.2
HighlightRegistry.set10510514017.210514017.2
HighlightRegistry.size10510514017.210514017.2
HighlightRegistry.values10510514017.210514017.2
highlight10510514917.210514917.2