MDN self-hosted library · e01.org

`::target-text` CSS pseudo-element

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.

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.

The ::target-text pseudo-element follows a special inheritance model common to all highlight pseudo-elements. For more details on how this inheritance works, see the Highlight pseudo-elements inheritance section.

Syntax

::target-text {
  /* ... */
}

Examples

Highlighting text fragments

::target-text {
  background-color: rebeccapurple;
  color: white;
}

To see this CSS in action follow the link to scroll-to-text demo.

Specifications

Browser compatibility

See also