v160 · javascript · cssom
CSSPseudoElement.selectorText
CSSPseudoElement lets script hold a pseudo-element — from element.pseudo(), CSSPseudoElement.pseudo() or event.pseudoTarget. Until now it only exposed type, the bare name: every ::view-transition-group(…) said "::view-transition-group", every scroll button said "::scroll-button". The new selectorText returns the full, normalized selector — "::view-transition-group(hero)", "::scroll-button(inline-start)" — in a form that round-trips into pseudo(), getComputedStyle() and animate().
concepts
-
type vs selectorText lab
Call
pseudo()with presets or your own string and readtypeandselectorTextside by side: legacy-colon normalization, whitespace removal, escaped identifiers, wildcard and unsupported types returningnull, and the round-trip check. -
pseudoTarget inspector
A devtools-style tool: click
::before,::afterand::markercontent, readevent.pseudoTarget, walk itsparentchain, and walk a nested view-transition chain where onlyselectorTexttells two snapshots apart. -
Round-trip into string APIs
A reusable helper that receives only a
CSSPseudoElementand must callgetComputedStyle,animate({pseudoElement})andpseudo():selectorTextworks; the oldtypeworkaround throwsSyntaxErroron parameterized pseudo-elements — run it inside a live view transition. -
View transition disambiguation
The motivating case: a real view transition with three named groups (one needing an escaped name). Same
typethree times, three differentselectorTextvalues, and a spotlight effect driven only by the objects — plus the unescapedKeyframeEffect.pseudoElementgotcha. -
Scroll-button directions
The edge case from CSSWG #14528:
pseudo("::scroll-button(left)")keepsleft, while a browser-createdpseudoTargetis always logical (inline-start/inline-end) — flip the carousel to RTL and watch the mapping. Needs a second flag.
how to run it
Chromium gates the attribute behind the Blink runtime feature CSSPseudoElementSelectorText (status experimental in runtime_enabled_features.json5; default-on target Chrome 160). There is no dedicated chrome://flags entry. Use any of:
chrome://flags/#enable-experimental-web-platform-features→ Enabled → relaunch.- Launch Chrome or Canary with
--enable-blink-features=CSSPseudoElementSelectorText. - Or
--enable-features=CSSPseudoElementSelectorText(the Finch feature name on ChromeStatus). - Or
--enable-experimental-web-platform-features.
The scroll-button concept additionally needs CSSPseudoElementScrollButton (also experimental, also covered by option 1). Every page detects the attribute with a behavioural probe that can return false and labels its fallback; none of them invents a selectorText value.
the API
[Exposed=Window]
interface CSSPseudoElement {
readonly attribute CSSOMString type; // "::view-transition-group"
readonly attribute Element element;
readonly attribute (Element or CSSPseudoElement) parent;
readonly attribute CSSOMString selectorText; // "::view-transition-group(hero)" ← new
CSSPseudoElement? pseudo(CSSOMString type);
};
const p = el.pseudo(":before");
p.type; // "::before"
p.selectorText; // "::before"
el.pseudo(p.selectorText) === p; // true — round-trips