CKTIS / CSS
::target-text — styling a text navigation target
The ::target-text pseudo-element styles text directly targeted by the document URL’s fragment, rather than an entire target element.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
::target-text { color: <color>; background-color: <color>; }::target-text represents text directly targeted by the document URL’s fragment. It is a highlight pseudo-element: it changes the targeted text’s appearance but does not itself search for text or initiate navigation.
Distinguish it from :target, the pseudo-class selecting a target element, and ::selection, which concerns selection. A fragment targeting an element, such as #chapter, does not by itself make ::target-text match.
Use color and background-color to establish a readable color pair. Highlights support a restricted property set; do not treat them as ordinary elements for layout changes. Test the example’s activation in the intended browser.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Target text demo</title>
<style>
::target-text {
color: #000000;
background-color: #ffff00;
}
</style>
<p>Find the cobalt lantern here.</p>
</html>Result
When opened through a supported text-fragment navigation targeting cobalt lantern, those words have black text on a yellow background. Ordinary navigation does not activate this rule.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.