Working Draft · css-pseudo

CSS Pseudo-Elements Module

13 selectors defined by this specification, all known to at least one browser .

Each feature in detail

::after

Selector Baseline: widely availablesince January 2018

Spec Represents a styleable child pseudo-element immediately after the originating element’s actual content.

MDN In CSS, ::after creates a pseudo-element that is the last child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.

Live preview Example from MDN
a::after {
  content: " (" attr(href) ")";
}

.dead-link {
  text-decoration: line-through;
}

.dead-link::after {
  content: url("https://developer.mozilla.org/shared-assets/images/examples/warning.svg");
  display: inline-block;
  width: 12px;
  height: 12px;
}

Syntax

::after

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Browser support

First browser version supporting ::after
Chrome 1
Edge 12
Firefox 1.5
Safari 4
Chrome Android 18
Safari iOS 3.2

First version with support, from MDN browser-compat-data.

::before

Selector Baseline: widely availablesince January 2018

Spec Represents a styleable child pseudo-element immediately before the originating element’s actual content.

MDN In CSS, ::before creates a pseudo-element that is the first child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.

Live preview Example from MDN
a {
  color: blue;
  text-decoration: none;
}

a::before {
  content: "🔗";
}

.local-link::before {
  content: url("https://developer.mozilla.org/shared-assets/images/examples/firefox-logo.svg");
  display: inline-block;
  width: 15px;
  height: 15px;
  margin-right: 5px;
}

Syntax

::before

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Browser support

First browser version supporting ::before
Chrome 1
Edge 12
Firefox 1.5
Safari 4
Chrome Android 18
Safari iOS 3

First version with support, from MDN browser-compat-data.

::details-content

Selector Baseline: newly availablesince September 2025 Modern CSS: ::details-content

Spec The ::details-content pseudo-element targets the additional information in a details element that can be expanded or collapsed. It is an element-backed pseudo-element.

MDN The ::details-content CSS pseudo-element represents the expandable/collapsible contents of a <details> element.

Live preview Example from MDN
details[open]::details-content {
  color: dodgerblue;
  padding: 0.5em;
  border: thin solid grey;
}

Syntax

::details-content

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Browser support

First browser version supporting ::details-content
Chrome 131
Edge 131
Firefox 143
Safari 18.4
Chrome Android 131
Safari iOS 18.4

First version with support, from MDN browser-compat-data.

::first-letter

Selector Baseline: widely availablesince January 2018

Spec The ::first-letter pseudo-element represents the first Letter, Number, or Symbol (Unicode category L*, N*, or S*) typographic character unit on the first formatted line of its originating element (the first letter) as well as its associated punctuation. Collectively, this text is the first-letter text. The ::first-letter pseudo-element can be used to create “initial caps” and “drop caps”, which are common typographic effects.

MDN The ::first-letter CSS pseudo-element applies styles to the first letter of the first line of a block container, but only when not preceded by other content (such as images or inline tables).

Live preview Example from MDN
p::first-letter {
  font-size: 1.5rem;
  font-weight: bold;
  color: brown;
}

Syntax

::first-letter

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Browser support

First browser version supporting ::first-letter
Chrome 1
Edge 12
Firefox 1
Safari 1
Chrome Android 18
Safari iOS 1

First version with support, from MDN browser-compat-data.

::first-line

Selector Baseline: widely availablesince January 2018

Spec The ::first-line pseudo-element represents the contents of the first formatted line of its originating element.

MDN The ::first-line CSS pseudo-element applies styles to the first line of a block container.

Live preview Example from MDN
p::first-line {
  font-size: 1.2rem;
  font-weight: bold;
  text-decoration: underline;
}

Syntax

::first-line

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Browser support

First browser version supporting ::first-line
Chrome 1
Edge 12
Firefox 1
Safari 1
Chrome Android 18
Safari iOS 1

First version with support, from MDN browser-compat-data.

::grammar-error

Selector Limited availability Modern CSS: ::spelling-error and ::grammar-error

Spec The ::grammar-error pseudo-element represents a portion of text that has been flagged by the user agent as grammatically incorrect.

MDN The ::grammar-error CSS pseudo-element represents a text segment which the user agent has flagged as grammatically incorrect.

Live preview Example from MDN
::grammar-error {
  text-decoration: underline red;
  color: red;
}

Syntax

::grammar-error

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Browser support

First browser version supporting ::grammar-error
Chrome 121
Edge 121
Firefox No
Safari 17.4
Chrome Android 121
Safari iOS 17.4

First version with support, from MDN browser-compat-data.

::highlight()

Selector Baseline: newly availablesince March 2026 Modern CSS: Custom highlights

MDN The ::highlight() CSS pseudo-element applies styles to a custom highlight.

Live preview Example from MDN
#rainbow-text {
  font-family: monospace;
  font-size: 1.5rem;
}

::highlight(rainbow-color-1) {
  color: violet;
  text-decoration: underline;
}
::highlight(rainbow-color-2) {
  color: purple;
  text-decoration: underline;
}
::highlight(rainbow-color-3) {
  color: blue;
  text-decoration: underline;
}
::highlight(rainbow-color-4) {
  color: green;
  text-decoration: underline;
}
::highlight(rainbow-color-5) {
  color: yellow;
  text-decoration: underline;
}
::highlight(rainbow-color-6) {
  color: orange;
  text-decoration: underline;
}
::highlight(rainbow-color-7) {
  color: red;
  text-decoration: underline;
}

Syntax

::highlight(<highlight-name-selector>)

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Browser support

First browser version supporting ::highlight()
Chrome 105
Edge 105
Firefox 149
Safari 17.2
Chrome Android 105
Safari iOS 17.2

First version with support, from MDN browser-compat-data.

::interest-button

Selector Limited availability Experimental Modern CSS: Interest invokers

Spec The ::interest-button pseudo-element represents a button which, when pressed, shows interest in the originating element. This pseudo-element only exists on valid interest sources. (See interest-delay, :interest-source, and :interest-target for more discussion of this feature, and the HTML interestfor attribute.)

Syntax

::interest-button

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Browser support

First browser version supporting ::interest-button
Chrome 149
Edge 149
Firefox No
Safari No
Chrome Android 149
Safari iOS No

First version with support, from MDN browser-compat-data.

::marker

Selector Limited availability

Spec The ::marker pseudo-element represents the automatically generated marker box of a list item. (See [CSS-DISPLAY-3] and [CSS-LISTS-3].)

MDN The ::marker CSS pseudo-element selects the marker box of a list item, which typically contains a bullet or number. It works on any element or pseudo-element set to display: list-item, such as the <li> and <summary> elements.

Live preview Example from MDN
li::marker {
  content: "✝ ";
  font-size: 1.2em;
}

Syntax

::marker

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Browser support

First browser version supporting ::marker
Chrome 86
Edge 86
Firefox 68
Safari 11.1
Chrome Android 86
Safari iOS 11.3

First version with support, from MDN browser-compat-data.

::search-text

Selector Experimental

Spec The ::search-text pseudo-element represents text identified by the user agent’s find-in-page feature. Since not all UAs style matched text in ways expressible with the highlight pseudo-elements, this pseudo-element is optional to implement. The :current pseudo-class (but not ::current()) may be combined with ::search-text to represent the currently focused match instance. The :past and :future pseudo-classes are reserved for analogous use in the future. Any unsupported combination of these pseudo-classes with ::search-text must be treated as invalid.

MDN The ::search-text CSS pseudo-element applies styles to search results identified by the user agent's "Find" or "Find in page" text search feature.

Live preview Example from MDN
p::search-text {
  color: crimson;
  background-color: wheat;
}

Syntax

::search-text

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Browser support

First browser version supporting ::search-text
Chrome 144
Edge 144
Firefox No
Safari No
Chrome Android 144
Safari iOS No

First version with support, from MDN browser-compat-data.

::selection

Selector Limited availability

Spec The ::selection pseudo-element represents the portion of a document that has been selected as the target or object of some possible future user-agent operation(s). It applies, for example, to selected text within an editable text field, which would be copied by a copy operation or replaced by a paste operation.

MDN The ::selection CSS pseudo-element applies styles to the part of a document that has been highlighted by the user (such as clicking and dragging the mouse across text).

Live preview Example from MDN
p::selection {
  color: red;
  background-color: yellow;
}

Syntax

::selection

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Browser support

First browser version supporting ::selection
Chrome 1
Edge 12
Firefox 62
Safari 1.1
Chrome Android 18
Safari iOS No

First version with support, from MDN browser-compat-data.

::spelling-error

Selector Limited availability Modern CSS: ::spelling-error and ::grammar-error

Spec The ::spelling-error pseudo-element represents a portion of text that has been flagged by the user agent as misspelled.

MDN The ::spelling-error CSS pseudo-element represents a text segment which the user agent has flagged as incorrectly spelled.

Live preview Example from MDN
::spelling-error {
  text-decoration: wavy red underline;
}

Syntax

::spelling-error

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Browser support

First browser version supporting ::spelling-error
Chrome 121
Edge 121
Firefox No
Safari 17.4
Chrome Android 121
Safari iOS 17.4

First version with support, from MDN browser-compat-data.

::target-text

Selector Baseline: newly availablesince December 2024 Modern CSS: ::target-text

Spec The ::target-text pseudo-element represents text directly targeted by the document URL’s fragment, if any.

MDN The ::target-text CSS pseudo-element represents the text that has been scrolled to if the browser supports text fragments. It allows authors to choose how to highlight that section of text.

Syntax

::target-text

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Browser support

First browser version supporting ::target-text
Chrome 89
Edge 89
Firefox 131
Safari 18.2
Chrome Android 89
Safari iOS 18.2

First version with support, from MDN browser-compat-data.