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.
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.
::target-text {
/* ... */
}
::target-text {
background-color: rebeccapurple;
color: white;
}
To see this CSS in action follow the link to scroll-to-text demo.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
::target-text |
89 | 89 | 131 | 75 | 18.2 | 89 | 131 | 63 | 18.2 | 15.0 | 89 | 18.2 |
:target (for highlighting target elements)
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/::target-text