This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The CSSPseudoElement interface represents a pseudo-element that may be the target of an event or animated using the Web Animations API. Instances of this interface may be obtained by calling Element.pseudo().


CSSPseudoElement.element This is an experimental API that should not be used in production code. Read only
Returns the originating/parent Element of the pseudo-element.
CSSPseudoElement.type This is an experimental API that should not be used in production code. Read only
Returns the pseudo-element selector as a CSSOMString.


CSSPseudoElement extends EventTarget, so it inherits the following methods:

Registers an event handler of a specific event type on the pseudo-element.
Dispatches an event to this pseudo-element.
Removes an event listener from the pseudo-element.


Basic example using Element.pseudo

Using pseudo-elements, most modern browsers will automatically add quotation marks around text inside a <q> element. (A style rule may be needed to add quotation marks in older browsers.) The example below demonstrates the basic properties of the CSSPseudoElement object representing the opening quotation mark.

const element = document.querySelector('q');
const cssPseudoElement = element.pseudo('::before');
console.log(cssPseudoElement.element); // Outputs [object HTMLQuoteElement]
console.log(cssPseudoElement.type); // Outputs '::before'


Specification Status Comment
CSS Pseudo-Elements Level 4
The definition of 'CSSPseudoElement' in that specification.
Working Draft Initial definition.

Browser compatibility

BCD tables only load in the browser

See also