CSSPseudoElement

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

EventTarget CSSPseudoElement

Instance properties

CSSPseudoElement.element Experimental Read only

Returns the originating/parent Element of the pseudo-element.

CSSPseudoElement.type Experimental Read only

Returns the pseudo-element selector as a string.

Instance methods

CSSPseudoElement extends EventTarget, so it inherits the following methods:

Examples

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.

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

Specifications

Specification
CSS Pseudo-Elements Module Level 4
# CSSPseudoElement-interface

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
CSSPseudoElement
Experimental
element
Experimental
type
Experimental

Legend

Tip: you can click/tap on a cell for more information.

No support
No support
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.

See also