::target-text

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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

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.

css
::target-text {
  background-color: pink;
}

Syntax

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

Examples

Highlighting text fragments

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

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

Specifications

Specification
CSS Pseudo-Elements Module Level 4
# selectordef-target-text

Browser compatibility

BCD tables only load in the browser

See also