Loading...
::target-text {
background: yellow;
padding: 2px;
border-radius: 4px;
}::target-text {
background: #ffe066;
color: #111;
}Only text styles apply to ::target-text, so padding and radius are dropped, and a set text color keeps contrast.
:target, which styles the element whose id matches the hash.::target-text keep readable contrast with the text.color and background-color are used; others are ignored.Add #:~:text= and the encoded phrase to a URL, like page.html#:~:text=color%20mix. The browser scrolls to the first match and highlights it.
No. The :~:text= part is removed from location.hash, so page scripts don't see it.