v158 · css · enabled by default
CSS Custom Highlight Universal Selector ::highlight(*)
::highlight(*) is a universal argument for the ::highlight() pseudo-element: it matches the highlight pseudo-elements of every custom highlight registered in CSS.highlights, whatever its name. The * argument contributes zero specificity, so its declarations act as a shared base style, and any rule that names a specific highlight overrides it property by property through the normal cascade.
at a glance
| Shipped in | Chrome 158 (desktop, Android, Android WebView), enabled by default — filed under “Enabled by default” in the milestone=158 listing; Chrome 158 stable date 2026-11-17 per the ChromeStatus channel schedule |
|---|---|
| Origin trial / flag | No origin trial, no user-facing flag. Blink runtime feature CSSCustomHighlightUniversalSelector has status stable in runtime_enabled_features.json5 (checked 2026-11-22) |
| Specification | CSS Pseudo-Elements Level 4 §3.1 — ::highlight(<highlight-name-selector>) (editor’s draft, Working Draft maturity) |
| CSSWG decision | w3c/csswg-drafts#9091 — “RESOLVED: Add * to highlight pseudo” and “RESOLVED: Specificity of * in highlight pseudo is 0” (2025-04-02); spec text landed in w3c/csswg-drafts#14301 (merged 2026-09-29) |
| Intents | Intent to Prototype; Intent to Ship (2026-10-14, three LGTMs) |
| Tracking bug | issues.chromium.org/408003366 |
| Web platform tests | css/css-highlight-api/custom-highlight-universal-* (parsing, escaped star, painting, inheritance) |
| ChromeStatus | 5174965228929024 — CSS Custom Highlight Universal Selector ::highlight(*) |
why it exists
Before Chrome 158, every registered highlight name needed its own rule. A page with spelling, grammar and search highlights that all wanted the same underline thickness had to repeat it three times, and a highlight registered later by another script got no styling at all — custom highlights have no UA default style, so an unstyled custom highlight is invisible. The ChromeStatus motivation: “Styling shared properties across custom highlights requires repeating the same declarations for every registered name.” In the Intent to Ship thread, the feature owner cited developer demand, including the MDN ::highlight() example that repeats text-decoration per name.
Syntax
Grammar from CSS Pseudo-Elements Level 4, quoted verbatim (fetched 2026-11-22):
::highlight(<highlight-name-selector>)
<highlight-name-selector> = '*' | <custom-ident>
“A <custom-ident> argument selects the single custom highlight whose custom highlight name is that identifier. The * argument selects every custom highlight, regardless of its custom highlight name.”
“The specificity of a ::highlight() selector with a <custom-ident> argument is equivalent to a type selector. The specificity of a ::highlight() selector with a * argument is zero.”
Typical forms of ::highlight(*):
::highlight(*) { /* every element, every custom highlight */ }
:root::highlight(*) { /* recommended document-wide base; inherited downwards */ }
article::highlight(*) { /* every custom highlight inside <article> elements */ }
This page documents three pieces of the change: the * argument and what it matches, the zero-specificity cascade with named rules, and inheritance of the universal base through the element tree. Supporting sections cover invalid selectors and fallbacks, context and applicable properties, and painting and lifecycle.
The * argument — inputs and what it matches
Input. ::highlight(*) takes exactly one token, an unescaped * (a <delim-token>, written '*' in the grammar). It is the only alternative to a single <custom-ident>; there is no namespace, list, or pattern form. It may follow any compound selector that names the originating element (div::highlight(*), :root::highlight(*)), or stand alone, in which case the originating element is the implied universal type selector, exactly as for ::selection.
| Selector | Valid? | Meaning |
|---|---|---|
::highlight(*) | Valid | Every custom highlight, on every element |
div::highlight(*), :root::highlight(*) | Valid | Every custom highlight, originating element restricted by the compound |
::highlight(foo) | Valid | Only the highlight registered as foo (unchanged pre-158 behaviour) |
::highlight(\*) | Valid | An escaped star is a <custom-ident>: it selects only a highlight registered under the literal name "*", and has type-selector specificity |
::highlight(), ::highlight(* foo), ::highlight(*.class), ::highlight(foo*), ::highlight(**) | Invalid | Selector fails to parse; the whole style rule is dropped |
Output. For every element matched by the compound selector, the declarations apply to that element’s highlight pseudo-element for each registered custom highlight name. They do not merge highlights into one overlay: each name is still cascaded and painted independently, so two overlapping highlights that both pick up a semi-transparent background-color from ::highlight(*) paint that background twice where they overlap. A highlight that has no named rule at all is painted with the ::highlight(*) values alone (WPT no-named-rule-001). ::highlight(*) matches custom highlights only — it does not match ::selection, ::target-text, ::search-text, ::spelling-error or ::grammar-error.
Errors: invalid selectors, older browsers and fallbacks
CSS has no exception path for a selector; the failure mode of ::highlight(*) is parse failure. A malformed argument (see the table above) — or any ::highlight(*) in an engine that predates the feature — makes the selector invalid, and an invalid selector invalidates the whole style rule, including every other selector in the same comma-separated list. Verified in headless Chrome 153 (pre-158) on 2026-11-22: CSSStyleSheet.insertRule("::highlight(*){…}") throws SyntaxError, while ::highlight(\*) parses.
Consequences you must design for:
- Do not list
::highlight(*)with named selectors in one rule (::highlight(*), ::highlight(spelling) { … }): older engines drop the named half too. Write the universal rule on its own. - Without the universal rule, named highlights get no base styling and an unnamed highlight stays invisible (no UA default). Keep a per-name fallback for engines that reject
*, either as plain repeated rules or gated with@supports not selector(::highlight(*)). - Feature detection:
CSS.supports("selector(::highlight(*))")and@supports selector(::highlight(*)). Pre-158 Chrome 153 returnsfalse(verified 2026-11-22); atrueresult in Chrome 158 follows from the selector being valid there but was not observed in this environment. getComputedStyle(el, "::highlight(*)")is not covered by any WPT assertion (WebKit removed its draft test for it in 320952@main); query a concrete name instead, e.g.getComputedStyle(el, "::highlight(spelling)"), which reflects the merged universal + named cascade.
selector() in @supports; WebKit bug 323469.
Zero specificity and the per-property cascade
The specificity of ::highlight(*) is (0,0,0) for the pseudo-element part, while ::highlight(foo) counts like a type selector, (0,0,1). Specificity of the originating-element compound is added as usual: div::highlight(*) is (0,0,1) and div::highlight(foo) is (0,0,2).
Algorithm. For each element and each registered highlight name N, the cascade for that element’s ::highlight(N) collects the declarations of every rule whose selector matches it — both …::highlight(N) and …::highlight(*) rules — and resolves each property separately by origin, layer, specificity and then source order. So:
- a named rule wins a conflicting property against a universal rule with the same originating compound, even when the universal rule comes later in source order (WPT
painting-002); - properties the named rule does not set are filled from
::highlight(*)(WPTpainting-001, andgetComputedStyle(outer, "::highlight(foo)")returns the namedcolorwith the universalbackground-color); - the base merges into each named highlight’s cascade independently (WPT
painting-003); - a more specific originating compound still wins:
#note::highlight(*)(1,0,0)beats::highlight(foo)(0,0,1).
| Property | Winning rule | Value |
|---|---|---|
color | ::highlight(foo) (higher specificity) | blue |
background-color | ::highlight(*) (only declaration) | yellow |
Inheritance of the universal base
Highlight pseudo-elements inherit through the originating element tree: when a supported property gets no value from the cascade (or inherit/unset), its value comes from the same-named highlight pseudo-element on the parent element, “regardless of whether that property is an inherited property.” Because ::highlight(*) contributes to every name’s cascade on the elements it matches, a :root::highlight(*) base reaches a named highlight on any descendant, through any number of elements that have no highlight rules (WPT inheritance-001, deep-chain-001). If a parent has both a universal and a named rule, the parent’s own cascade decides first — the child inherits the named value (WPT inheritance-computed).
Pitfall — prefer :root::highlight(*). An unqualified ::highlight(*) means *::highlight(*): it matches on every element, so on a descendant it is a specified value that beats a value the descendant would otherwise have inherited from an ancestor’s named rule. Given p::highlight(foo) { color: blue } and ::highlight(*) { color: red }, text of foo inside an <em> in that paragraph is red. This is the same trap the spec describes for ::selection versus :root::selection; with :root::highlight(*) the base is inherited instead, and the paragraph’s blue reaches the <em>.
:root::selection example); WPT inheritance-001; WPT deep-chain-001; WPT inheritance-computed.
Context: where it applies and which properties work
::highlight(*) is a selector, usable in any author style sheet (<style>, <link>, constructed CSSStyleSheet, shadow-tree style sheets). It needs no permission, secure context or JavaScript; only the highlights themselves are created from script via CSS.highlights.set(name, new Highlight(...ranges)). The originating element is whatever the compound before ::highlight(*) selects; without one it is every element.
Only the restricted highlight property set applies, exactly as for named highlights: color, background-color, text-decoration and its longhands (including text-underline-position, text-underline-offset), text-shadow, stroke-color, fill-color, stroke-width, and custom properties. Other properties (for example background-image, font-weight) are ignored. The spec notes that historically only color and background-color have been interoperable.
Painting and lifecycle
::highlight(*) is matched by name at style time, not bound to the names registered when the style sheet loaded: a highlight added to CSS.highlights later is styled by the existing universal rule on the next rendering update, and a deleted one stops painting. Registry additions/removals, range changes and priority changes trigger an asynchronous repaint — no API call blocks on it. Each custom highlight name paints its own overlay, stacked by Highlight.priority (ties: most recently registered on top), all below ::selection, ::target-text, ::spelling-error and ::grammar-error. A single Highlight registered under two names is painted twice, so a universal background applies twice to it. Removing or disabling the universal rule (e.g. removing a constructed sheet from document.adoptedStyleSheets) restyles all highlights at once.
Examples
insertRule and shows the per-name fallback in pre-158 engines).Source: chrome-platform-showcase — ::highlight(*)A complete page: three highlights, one shared ::highlight(*) base, named rules for what differs, and a fallback for engines without *:
<p id="text">Teh quick brown fox jump over the lazy dog.</p>
<style>
/* Shared base for every custom highlight (Chrome 158+). */
:root::highlight(*) {
text-decoration-line: underline;
text-decoration-thickness: 2px;
text-underline-offset: 3px;
}
/* Named rules override per property (specificity 0,0,1 beats 0,0,0). */
::highlight(spelling) { text-decoration-color: red; text-decoration-style: wavy; }
::highlight(grammar) { text-decoration-color: blue; }
::highlight(search) { background-color: yellow; color: black; }
/* Fallback: older engines reject ::highlight(*) entirely. */
@supports not selector(::highlight(*)) {
::highlight(spelling) { text-decoration-line: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
::highlight(grammar) { text-decoration-line: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
::highlight(search) { text-decoration-line: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
}
</style>
<script>
const t = document.getElementById("text").firstChild;
const at = (start, end) => {
const r = new Range();
r.setStart(t, start);
r.setEnd(t, end);
return r;
};
CSS.highlights.set("spelling", new Highlight(at(0, 3))); // "Teh"
CSS.highlights.set("grammar", new Highlight(at(20, 24))); // "jump"
CSS.highlights.set("search", new Highlight(at(16, 19))); // "fox"
</script>
Source: css-pseudo-4 §3.1; CSS Custom Highlight API — creating and registering highlights.
Base style plus named override
Mirrors WPT painting-001: highlight foo paints blue text on yellow — color from the named rule, background-color from ::highlight(*). Swapping the two rules’ order changes nothing (painting-002).
::highlight(*) { background-color: yellow; color: red; }
::highlight(foo) { color: blue; }
/* In script: */
const r = new Range();
r.setStart(document.body, 0);
r.setEnd(document.body, 2);
CSS.highlights.set("foo", new Highlight(r));
getComputedStyle(document.body, "::highlight(foo)").color; // "rgb(0, 0, 255)"
getComputedStyle(document.body, "::highlight(foo)").backgroundColor; // "rgb(255, 255, 0)"
Source: WPT painting-001; WPT computed-style assertions.
Document-wide base inherited by descendants
Mirrors WPT deep-chain-001: the pink background set once on :root reaches the foo highlight inside nested elements that have no highlight rules, while the span’s own named rule supplies the colour.
<style>
:root::highlight(*) { background-color: pink; }
span::highlight(foo) { color: green; }
</style>
<div><div><span id="target">One two three</span></div></div>
<script>
const text = document.getElementById("target").firstChild;
const r = new Range();
r.setStart(text, 0);
r.setEnd(text, 8);
CSS.highlights.set("foo", new Highlight(r)); // "One two " paints green on pink
</script>
Source: WPT deep-chain-001; css-pseudo-4 §3.5.
Feature detection from script
const supportsUniversal = CSS.supports("selector(::highlight(*))");
const sheet = new CSSStyleSheet();
try {
sheet.insertRule(":root::highlight(*) { text-decoration-line: underline; }");
} catch (e) {
// SyntaxError in engines without ::highlight(*): fall back to one rule per name.
for (const name of CSS.highlights.keys()) {
sheet.insertRule(`::highlight(${CSS.escape(name)}) { text-decoration-line: underline; }`);
}
}
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
The fallback branch only styles names registered before it runs; that is exactly the gap ::highlight(*) closes.
selector(); CSSOM insertRule() (throws SyntaxError on an unparsable rule); showcase universal-base-style uses the same probe.
Browser compatibility
| Browser | ::highlight(*) | Evidence / notes | Parent ::highlight(<custom-ident>) (BCD) |
|---|---|---|---|
| Chrome (desktop, Android), Android WebView | 158 | Enabled by default per ChromeStatus; wpt.fyi Chrome 160 canary passes every custom-highlight-universal test | 105 |
| Edge | Unknown (no BCD entry) | The wpt.fyi Edge 158.0.4370.33 run passes parsing and painting tests but 1 of 2 inheritance-computed subtests | 105 (mirror) |
| Firefox | No release | Mozilla position: positive. Firefox Nightly 163.0a1 on wpt.fyi passes parsing and painting-001/002/003 but fails the inheritance and deep-chain tests — partial, unreleased | 149 (140–148 partial) |
| Safari | No release | WebKit position: support; implemented in WebKit trunk (bug 323469, fixed 2026-09-11, 320952@main). The wpt.fyi Safari 27.2 stable run fails the painting tests | 17.2 |
* subfeature); wpt.fyi custom-highlight-universal results; ChromeStatus API record; webstatus.dev Custom highlights.
Security and privacy
::highlight(*) adds a selector argument and no new data source, storage, network request or permission. It only styles ranges the page itself registered in CSS.highlights, and only with the paint-only highlight properties, so it cannot change layout. It does not match ::spelling-error or ::grammar-error, the highlights whose styling the spec flags as able to leak a user’s dictionary contents. The CSS Custom Highlight API states it is “not thought to introduce any new security concern” or privacy concern; css-pseudo-4 records no new privacy considerations. Chromium’s security and privacy reviews for this entry are listed as “Pending” in the ChromeStatus record (checked 2026-11-22).
Specifications
see also
- MDN —
::highlight()(covers named highlights; no*argument as of 2026-11-22) - MDN — CSS Custom Highlight API
- w3c/csswg-drafts#9091 — the proposal and resolutions
- chromestatus — CSS Custom Highlight Universal Selector ::highlight(*) (5174965228929024)
- chrome-platform-showcase — live demos (zero-specificity cascade, multi-category annotator)