::highlight() - CSS Selector
Summary of characteristics of the ::highlight() selector
::highlight() pseudo-element - Description.
::highlight() targets the text highlighted by JavaScript using the CSS Custom Highlight API library. This library lets you select
parts of text anywhere on the page.
The operation requires several steps:
- Create one or more
Rangeobjects that each define a portion of text to highlight. - Group these objects into a
Highlightobject. - Link this object to a CSS-usable identifier.
- Use
::highlight()with this ID to target the texts.
Few properties can apply to ::highlight():
- The color of the text.
- The background color.
text-decorationand the detailed properties. ⚠- Text shadow (
text-shadow). ⚠
The example below searches for the entered word within the text of the description section of this page. It is first searched without
considering case (highlighted in light blue), then with case sensitivity (highlighted in blue).
Compared to a classic search, this has the advantage of only looking in the desired spots, and not in the table of contents, for example. On the other hand,
since the search is done in JavaScript, we have complete freedom to do whatever we want, here distinguishing texts that respect case from those that don’t.
::highlight() pseudo-element - Browser compatibility.
Relatively new, the pseudo-element ::highlight() is now well recognized by browsers, with a few exceptions.
::highlight which targets texts highlighted by Javascript.Notes:
(1) The pseudo element ::highlight cannot be used with text-decoration and text-shadow.
(2) The pseudo-element ::highlight is ignored when combined with user-select:none.
::highlightpseudo-element
Browsers on computers :
Mobile browsers :
Outdated or marginal browsers :

Internet Explorer

UC Browser pour Androïd

Opéra Mobile

QQ Browser

Baidu Browser

Samsung Internet

Chrome

Edge

Opéra

Safari

Safari sur IOS

Firefox

Androïd Brower

Chrome pour Androïd

Firefox pour Androïd

KaiOS Browser

Opéra mini
::highlight() pseudo-element - Historic.
-
CSS Pseudo-Elements Module Level 4
Regarding::highlight()Introduction of pseudo-element::highlight.January 15, 2015Working Draft.
See also...
Some pseudo-elements target the result of a search. Here are the main ones:





