← Chrome 160 reference · All APIs
v160 · cssom · enabled by default
CSSPseudoElement.selectorText
The read-only CSSPseudoElement.selectorText property returns the full, normalized CSS selector string for a pseudo-element — including any functional arguments such as ::view-transition-group(hero) or ::scroll-button(inline-end) — in a form that round-trips cleanly back into Element.pseudo(), CSSPseudoElement.pseudo(), getComputedStyle(), and Element.animate().
at a glance
| Shipped in | Chrome 160 (desktop, Android, Android WebView) — listed under “Enabled by default” in the milestone=160 listing and targeted for Chrome 160 in the ChromeStatus API record |
|---|---|
| Origin trial / flag | No origin trial, no user-facing chrome://flags entry. Blink runtime feature CSSPseudoElementSelectorText (depends on CSSPseudoElementInterface; currently status: "experimental" in runtime_enabled_features.json5; testable on earlier builds via --enable-blink-features=CSSPseudoElementSelectorText) |
| Specification | CSS Pseudo-Elements Module Level 4 §7.1 CSSPseudoElement.selectorText (CSSWG PR #13169) |
| CSSWG issues | w3c/csswg-drafts#12161 (retrieving pseudo-element arguments); w3c/csswg-drafts#14528 (::scroll-button() direction serialization) |
| Explainer | CSSPseudoElement.selectorText explainer |
| Intent | blink-dev Intent to Prototype; blink-dev Intent to Ship |
| Tracking bug | issues.chromium.org/567978984 |
| Web platform tests | wpt.fyi — css/css-pseudo/CSSPseudoElement-selectorText.html (WPT source) |
| ChromeStatus | 5071155760332800 — CSSPseudoElement.selectorText |
why it exists
CSSPseudoElement.type returns only the base pseudo-element identifier without functional arguments — for example, "::view-transition-group" or "::scroll-button". For parameterized pseudo-elements, type cannot distinguish ::view-transition-group(hero) from ::view-transition-group(sidebar) or tell which ::scroll-button() direction received an event on event.pseudoTarget. Adding selectorText preserves type as a clean category check while exposing the exact normalized selector string (including escaped arguments) needed to disambiguate instances and call string-based APIs like getComputedStyle() and Element.animate().
Syntax
WebIDL from CSS Pseudo-Elements Module Level 4 §7.1 (the selectorText attribute is the Chrome 160 addition; type, element, parent, and pseudo() are pre-existing members of CSSPseudoElement shown for interface context):
[Exposed=Window]
interface CSSPseudoElement {
readonly attribute CSSOMString type;
readonly attribute Element element;
readonly attribute (Element or CSSPseudoElement) parent;
readonly attribute CSSOMString selectorText;
CSSPseudoElement? pseudo(CSSOMString type);
};
“The
selectorTextattribute is a string representing the full, normalized selector text used to select the pseudo-element. This includes the pseudo-element name and any arguments, serialized in a form that can round-trip. For example,"::after"for a::afterpseudo-element, or"::scroll-button(left)"for a::scroll-button()pseudo-element with aleftargument.”
This reference covers the two parts of the Chrome 160 contract: the CSSPseudoElement.selectorText property contract and its CSSOM normalization and serialization rules (including ::view-transition-* identifiers and ::scroll-button() directions).
CSSPseudoElement.selectorText (fetched 2026-11-24); Blink css_pseudo_element.idl.
CSSPseudoElement.selectorText — inputs and outputs
Inputs. selectorText is a read-only getter on CSSPseudoElement instances and takes no arguments. Instances are obtained via element.pseudo(type), cssPseudoElement.pseudo(type), or event properties such as event.pseudoTarget.
Outputs. Returns a CSSOMString containing the canonical double-colon pseudo-element name in lowercase, followed by (argument) whenever the pseudo-element carries an argument. For a nested sub-pseudo-element (such as target.pseudo("::before").pseudo("::marker")), selectorText returns only its own pseudo-element selector ("::marker"), not a compound chain — walk pseudo.parent.selectorText ("::before") to inspect ancestors.
How the CSSPseudoElement was obtained | type | selectorText |
|---|---|---|
el.pseudo("::before") / el.pseudo(":before") / el.pseudo("::BEFORE") | "::before" | "::before" |
el.pseudo("::before").pseudo("::marker") | "::marker" | "::marker" (own segment only) |
el.pseudo("::scroll-button(left)") | "::scroll-button" | "::scroll-button(left)" |
el.pseudo("::scroll-button( inline-start )") | "::scroll-button" | "::scroll-button(inline-start)" |
Browser-created scroll button (e.g. event.pseudoTarget) | "::scroll-button" | "::scroll-button(inline-start)" (logical direction) |
pair.pseudo("::view-transition-old(header)") | "::view-transition-old" | "::view-transition-old(header)" |
Serialization rules — normalization, escaping, and ::scroll-button()
In Chromium’s CSSPseudoElement::selectorText() implementation, serialization starts from the canonical lowercase double-colon tag name (::before, ::after, ::marker, ::backdrop, ::scroll-marker, ::scroll-button, ::view-transition, ::view-transition-group, ::view-transition-image-pair, ::view-transition-old, ::view-transition-new) and appends (<argument>) when an argument is present:
- Case and legacy-colon normalization: Legacy single-colon forms (
":before",":after") normalize to double-colon syntax ("::before","::after"), ASCII case normalizes to lowercase ("::BEFORE"→"::before"), and surrounding whitespace inside parentheses is stripped ("::scroll-button( inline-start )"→"::scroll-button(inline-start)"). ::view-transition-*<custom-ident>escaping: For parameterized view-transition pseudo-elements (::view-transition-group(),::view-transition-image-pair(),::view-transition-old(),::view-transition-new()), Blink serializes the argument withSerializeIdentifier()so identifiers requiring CSS escapes still round-trip throughparent.pseudo(pseudo.selectorText),getComputedStyle(), andelement.animate().::scroll-button()physical vs logical directions (CSSWG #14528):::scroll-button()accepts physical keywords (left,right,up,down) and logical keywords (inline-start,inline-end,block-start,block-end). Fixed direction keywords are appended directly without identifier escaping. Author-created instances (fromel.pseudo()) preserve the coordinate space the caller passed ("left"stays"::scroll-button(left)";"inline-start"stays"::scroll-button(inline-start)"). Browser-created instances (such asevent.pseudoTarget) serialize using logical directions (e.g."::scroll-button(inline-start)").
Errors, edge cases, and feature detection
Reading pseudo.selectorText never throws an exception. Because selectorText is a read-only attribute on CSSPseudoElement.prototype, assigning to it silently fails in sloppy mode and throws a TypeError in strict mode.
- Invalid or unsupported pseudo-element selectors:
element.pseudo(selector)returnsnull(rather than throwing) for malformed selectors, element-backed or unsupported pseudo-elements, wildcard arguments ("::scroll-button(*)"or"::view-transition-group(*)"), or skipping levels in the view-transition hierarchy (for example calling::view-transition-image-pair(hero)directly on::view-transitioninstead of on its direct parent::view-transition-group(hero)). Always null-check before readingselectorText. - Feature detection: Check
typeof CSSPseudoElement !== "undefined" && "selectorText" in CSSPseudoElement.prototype. In Chrome 149–159 (whereCSSPseudoElementexists withoutselectorText), readingpseudo.selectorTextevaluates toundefined; fall back topseudo.selectorText ?? pseudo.typewhen arguments are optional.
Context and exposure
CSSPseudoElement and its selectorText attribute are exposed in Window contexts only ([Exposed=Window]; not available in Web Workers). No secure context, permission, or user activation is required. As verified by WPT CSSPseudoElement-selectorText.html, selectorText works identically on disconnected elements created with document.createElement("div") and on elements that do not currently generate a box for that pseudo-element.
Lifecycle and object identity
Per CSS Pseudo-Elements 4 §7.2 and Blink’s CSSPseudoElementsCacheData, repeated lookups for the same (originating element, pseudo_id, argument) return the same cached CSSPseudoElement object identity, so el.pseudo(p.selectorText) === p (or p.parent.pseudo(p.selectorText) === p for sub-pseudo-elements) holds across round trips. The serialized selectorText of a CSSPseudoElement instance is immutable over that object’s lifetime: as noted in CSS Pseudo-Elements 4, changing writing-mode does not rewrite a previously created physical ::scroll-button(left) object’s selectorText, even though it may resolve to a different flow-relative button at layout time.
Examples
Interactive lab & disambiguating ::scroll-button() and ::view-transition-*
CSSPseudoElement.type and CSSPseudoElement.selectorText. Source: Chrome Platform Showcase — CSSPseudoElement.selectorText.// 1. Disambiguate browser-created ::scroll-button() clicks and round-trip
// selectorText into getComputedStyle() and element.animate().
carousel.addEventListener("click", (event) => {
const pseudo = event.pseudoTarget;
if (pseudo?.type !== "::scroll-button") return;
// Browser-created scroll buttons serialize with logical directions:
if (pseudo.selectorText === "::scroll-button(inline-end)") {
const { opacity } = getComputedStyle(pseudo.element, pseudo.selectorText);
pseudo.element.animate([{ opacity }, { opacity: 0.4 }, { opacity }], {
duration: 240,
pseudoElement: pseudo.selectorText,
});
}
});
// 2. Author-created scroll buttons preserve their coordinate space:
const physical = carousel.pseudo("::scroll-button(left)");
physical?.selectorText; // "::scroll-button(left)"
const logical = carousel.pseudo("::scroll-button( inline-start )");
logical?.selectorText; // "::scroll-button(inline-start)"
// 3. Nested view-transition pseudo-elements return only their own segment:
const vt = document.documentElement.pseudo("::view-transition");
const group = vt?.pseudo("::view-transition-group(hero)");
const pair = group?.pseudo("::view-transition-image-pair(hero)");
const oldSnap = pair?.pseudo("::view-transition-old(hero)");
oldSnap?.type; // "::view-transition-old"
oldSnap?.selectorText; // "::view-transition-old(hero)"
oldSnap?.parent === pair; // true
Additional interactive demos on the Chrome Platform Showcase cover the pseudoTarget inspector, round-tripping into string APIs, view transition disambiguation, and scroll-button directions.
Feature-detecting CSSPseudoElement.selectorText
function supportsPseudoSelectorText() {
return (
typeof CSSPseudoElement !== "undefined" &&
"selectorText" in CSSPseudoElement.prototype
);
}
function describePseudo(pseudo) {
if (!pseudo) return null;
// Falls back to base type on Chrome 149-159 where selectorText is absent
return supportsPseudoSelectorText() ? pseudo.selectorText : pseudo.type;
}
Source: CSS Pseudo-Elements 4 §7.1; BCD api/CSSPseudoElement.json.
Browser compatibility
| Browser | selectorText | Evidence / notes | Base CSSPseudoElement (BCD) |
|---|---|---|---|
| Chrome (desktop, Android, WebView) | 160 | Targeted for Chrome 160 across desktop, Android, and WebView per ChromeStatus 5071155760332800 (runtime flag CSSPseudoElementSelectorText) | 149 |
| Edge | 160 (dev) | Chromium-based; wpt.fyi Edge 160.0.4408.0 passes 4/4 subtests (2026-11-24) | 149 (mirror) |
| Firefox | No support | Mozilla standards position #1489: No signal | 75 (behind pref dom.css_pseudo_element.enabled) |
| Safari | No support | WebKit standards position #744: No signal | No support |
Security and privacy
CSSPseudoElement.selectorText is a read-only string serializer for pseudo-element references the script already holds. It exposes only CSS pseudo-element type names and selector arguments (such as author-defined view-transition-name identifiers or standard logical ::scroll-button() direction keywords). It introduces no new storage, network capability, permission prompt, or cross-origin data exposure. ChromeStatus 5071155760332800 records no security risks, and CSS Pseudo-Elements 4 Security & Privacy Considerations raise no additional concerns for selectorText.