v147 · CSS · JavaScript
CSSPseudoElement interface
Element.pseudo('::before') returns a live CSSPseudoElement object, letting JavaScript inspect and measure pseudo-elements like real DOM nodes — geometry queries, computed styles, and event attribution included.
concepts
-
Pseudo-element Inspector
Pick an element and a pseudo-type (
::before,::after,::marker). CallsgetBoundingClientRect()andgetComputedStyle()on the returnedCSSPseudoElementand displays the live values. -
PseudoTarget Events
Hover over elements to trigger CSS transitions on their
::beforepseudo-elements. The newevent.pseudoTargetproperty onTransitionEventtells you exactly which pseudo-element fired the event — no more guessing. -
Pseudo-element Geometry Queries
Calls
Element.pseudo('::before').getBoundingClientRect()and draws canvas overlays showing the exact pixel geometry of::beforeand::afterdecorators — demonstrating the geometry API that was impossible beforeCSSPseudoElement. -
Style Mutation Probe
A live polling probe that reads
getComputedStyle()on::beforeand::afterpseudo-elements at 10 Hz viaElement.pseudo(). Hover and click the cards to trigger CSS transitions — watch exactly which properties change in the probe panel, without any JavaScript modifying the styles directly. -
Compatibility Lab
Probes
Element.pseudo(),CSSPseudoElement.getBoundingClientRect(), andevent.pseudoTargetvia feature detection. Runs a livegetComputedStyle()call on a::beforepseudo-element to confirm the API works. Provides the polyfill fallback for non-supporting browsers.
why it shipped
Pseudo-elements like ::before and ::after have always been invisible to JavaScript. You couldn't query their geometry, read their computed styles, or know when a CSS animation fired on one. Workarounds involved creating real DOM nodes instead of pseudo-elements, or reading getComputedStyle(el, '::before') and manually parsing the content. The CSSPseudoElement interface closes this gap: element.pseudo('::before') returns a proxy object that supports getBoundingClientRect(), getComputedStyle(), and serves as the pseudoTarget on animation and transition events. The same interface also ships in Firefox, making this an interoperability milestone.
references
implementation reference
Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗