Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

::search-text — styling find-in-page matches

::search-text styles text found by the browser's find-in-page feature. The ::search-text:current variant distinguishes the current match; support needs verification.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

::search-text { color: black; background-color: yellow; }
::search-text:current { background-color: orange; }

::search-text represents text found by the browser's find-in-page feature. It neither starts a search nor accepts a search string. Unlike ::selection, it does not represent user-selected text.

::search-text:current identifies the currently focused match. It uses the :current pseudo-class, not ::current(). :past and :future are reserved for future use; unsupported combinations are invalid.

This is a highlight pseudo-element: use color and background-color, rather than treating it as an ordinary layout element. Implementation is optional. To try the example, manually search for orchid. The example code and declared result were verified in an isolated environment. Check rendering in the target browser instead of assuming support from a version scope.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Search highlight demo</title>
<style>
p::search-text {
  color: #000;
  background-color: #ffeb3b;
}
p::search-text:current {
  background-color: #ff9800;
}
</style>
<p>orchid / orchid / orchid</p>
</html>

Result

With both selectors supported and find-in-page searching for orchid: three matches, with black text; the focused match has an orange background (#ff9800), and the other matches have yellow backgrounds (#ffeb3b). Advancing to the next match moves the orange highlight.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources