::target-text
Baseline 2024Newly available
Since December 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
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
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
::target-text |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.