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().

Probing this browser…

concepts

  1. type vs selectorText lab

    Call pseudo() with presets or your own string and read type and selectorText side by side: legacy-colon normalization, whitespace removal, escaped identifiers, wildcard and unsupported types returning null, and the round-trip check.

  2. pseudoTarget inspector

    A devtools-style tool: click ::before, ::after and ::marker content, read event.pseudoTarget, walk its parent chain, and walk a nested view-transition chain where only selectorText tells two snapshots apart.

  3. Round-trip into string APIs

    A reusable helper that receives only a CSSPseudoElement and must call getComputedStyle, animate({pseudoElement}) and pseudo(): selectorText works; the old type workaround throws SyntaxError on parameterized pseudo-elements — run it inside a live view transition.

  4. View transition disambiguation

    The motivating case: a real view transition with three named groups (one needing an escaped name). Same type three times, three different selectorText values, and a spotlight effect driven only by the objects — plus the unescaped KeyframeEffect.pseudoElement gotcha.

  5. Scroll-button directions

    The edge case from CSSWG #14528: pseudo("::scroll-button(left)") keeps left, while a browser-created pseudoTarget is 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:

  1. chrome://flags/#enable-experimental-web-platform-features → Enabled → relaunch.
  2. Launch Chrome or Canary with --enable-blink-features=CSSPseudoElementSelectorText.
  3. Or --enable-features=CSSPseudoElementSelectorText (the Finch feature name on ChromeStatus).
  4. 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

references