• About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
AimactGrow
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
AimactGrow
No Result
View All Result

::search-text | CSS-Methods

Admin by Admin
June 2, 2026
Home Coding
Share on FacebookShare on Twitter


The CSS ::search-text pseudo-element selects matching textual content out of your browser’s “discover in web page” characteristic. For instance, when you use your browser search to seek out “search-text” on this web page, all cases of it’s going to spotlight. This pseudo-element lets us type the looks of that spotlight.

And a bonus! If there are a number of matches on the web page, then ::search-text can be utilized with the :present pseudo-class to type the match that’s at present in focus.

You’ll be able to “discover in web page” utilizing the CTRL + F (for Home windows) or "⌘F" (for Mac) keyboard shortcuts.

::search-text {
  background: oklch(87% 0.17 90) /* yellow */;
  coloration: black;
}

::search-text:present {
  background: oklch(62% 0.22 38) /* pink */;
  coloration: white;
}

The CSS ::search-text pseudo-element is outlined within the CSS Pseudo-Components Module Degree 4 specification.

Syntax

Fairly simple! Declare the pseudo-element and add your type guidelines:

::search-text{
  /* ... */
}

Utilization

It’s sometimes declared by itself (::search-text), however may be appended to particular parts as effectively:

/* All textual content */
::search-text {}
html::search-text {} /* sort of redundant */
/* Particular aspect */
part::search-text {}
robust::search-text {}

We’re just a little restricted so far as what CSS properties we are able to declare in ::search-text. Here’s what it helps:

And, sure, we are able to use it with customized properties, like:

:root {
  --color-blueberry: oklch(0.5458 0.1568 241.39);
}
::search-text {
  background-color: var(--color-blueberry);
}

Fundamental utilization

With the ::search-text pseudo-element, we are able to type the matching textual content outcomes from “Discover in web page”. Plus, if we need to type the at present targeted matching textual content, then we connect the :present pseudo-class after ::search-text.

/* matches all searched textual content */
::search-text {
  coloration: inexperienced;
  background-color: white;
}
/* matches any header stage 1 searched textual content */
h1::search-text {
  text-shadow: 12px 1px lightgrey;
  background-color: black;
  coloration: white;
}
/* the present searched header stage 1 textual content */
h1::search-text:present {
  coloration: pink;
  background: white;
}

Inheritance chain

All descendants all the time inherit kinds utilized by the spotlight pseudo-elements. This manner, particular person properties set on highlights will cascade to all parts down the three. Take for instance the next HTML:

Spotlight inheritance demo

Lorem ipsum dolor sit amet. Lorem seems once more right here. One other lorem seems right here.

We have now an 

 container with two kids: 

 and , the latter having a  descendant of its personal. We may type ::search-text in 

 with the next CSS, which might apply to all parts in 

:

article::search-text {
  background: gold;
  coloration: black;
  text-decoration: underline;
}

Then, override the coloration property for less than  and its descendants:

p::search-text {
  coloration: orange;
}

And do the identical for text-decoration on the  aspect:

robust::search-text {
  text-decoration: line-through;
}

While you seek for “lorem”, the background of the primary occasion (inside  however exterior ) will inherit each the background and text-decoration values from 

, whereas overriding its coloration worth with its personal orange.

Onto ‘s “lorem” textual content, it’s going to inherit the properties we set in its father or mother  and grandparent 

. So the coloration and background values are inherited immediately from its father or mother, and since they haven’t been overridden, they keep. Whereas we override the text-decoration worth to line-through.

The important thing takeaway from this instance is that properties for spotlight parts are additionally individually inherited and overridden.

Focusing on a textual content

Within the demo beneath, we set text-decoration to underline to provide any searched textual content a blue underline. This manner, we are able to customise matching textual content whereas additionally leaving the default background coloration, which prevents folks from getting confused about what’s happening.

::search-text {
  text-decoration: underline;
  text-decoration-color: oklch(65% 0.18 240);
  text-decoration-thickness: 0.22em;
  text-underline-offset: 0.15em;
}

Utilizing :present

Utilizing ::search-text with :present, we are able to type the at present targeted match. For instance, beneath we apply a light-weight orange hue textual content ornament coloration with 0.3em thickness to the at present matched searched textual content:

::search-text:present {
  text-decoration-color: oklch(85% 0.22 38);
  text-decoration-thickness: 0.3em;
}

Some accessibility notes

For WCAG’s distinction requirements, you want a distinction ratio of not less than 4.5:1 between the textual content and background. One other piece of recommendation is to not change the search colours an excessive amount of. In reality, this characteristic needs to be used sparingly since it might trigger points for customers with cognitive points, and as a core a part of the browser, it may be typically complicated. My private recommendation is to stay to solely text-decoration and its related properties since they’re extra refined than the remainder.

There’s additionally :previous and :future

The :previous and :future pseudo-classes are purported to match the aspect solely prior and completely after a :present aspect, respectively.

Nonetheless, the specification says:

The :previous and :future pseudo-classes are reserved for analogous use sooner or later. Any unsupported mixture of those pseudo-classes with ::search-text have to be handled as invalid

Which means, you may’t use :previous, :future or every other pseudo-class with the ::search-text pseudo-element. In case your browser by some means works with them, kindly report the sudden habits by opening a difficulty with them.

Specification

The CSS ::search-text pseudo-element is outlined within the CSS Pseudo-Components Module Degree 4 specification. That is nonetheless being examined and improved upon.

Browser help

Very extensive help:

Associated methods!

Associated

Tags: CSSTrickssearchtext
Admin

Admin

Next Post
Monopoly Go x The Simpsons crossover is sort of right here

Monopoly Go x The Simpsons crossover is sort of right here

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended.

Fortnite Is Including Darth Jar Jar and a Star Wars-Themed Battle Go for Its Galactic Battle Season

Fortnite Is Including Darth Jar Jar and a Star Wars-Themed Battle Go for Its Galactic Battle Season

April 20, 2025
Finest Black Friday Software program Offers in 2025: AI, CRM, and Extra

Finest Black Friday Software program Offers in 2025: AI, CRM, and Extra

September 30, 2025

Trending.

Nsfw Chatgpt Options – Examples I’ve Used

Nsfw Chatgpt Options – Examples I’ve Used

October 13, 2025
Undertaking possession (fairness and fairness)

Your work diary | Seth’s Weblog

May 6, 2026
The Obtain: the tech reshaping IVF and the rise of balcony photo voltaic

The Obtain: the tech reshaping IVF and the rise of balcony photo voltaic

May 7, 2026
From Shader Uniforms to Clip-Path Wipes: How GSAP Drives My Portfolio

From Shader Uniforms to Clip-Path Wipes: How GSAP Drives My Portfolio

May 7, 2026
Digital Detox & Display Time Statistics 2025

Digital Detox & Display Time Statistics 2025

March 28, 2026

AimactGrow

Welcome to AimactGrow, your ultimate source for all things technology! Our mission is to provide insightful, up-to-date content on the latest advancements in technology, coding, gaming, digital marketing, SEO, cybersecurity, and artificial intelligence (AI).

Categories

  • AI
  • Coding
  • Cybersecurity
  • Digital marketing
  • Gaming
  • SEO
  • Technology

Recent News

Asserting the First Batch of Audio system for MozCon NYC 2026

Asserting the First Batch of Audio system for MozCon NYC 2026

June 3, 2026
Infinity isn’t a quantity

Professionals know how one can discuss it

June 3, 2026
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us

© 2025 https://blog.aimactgrow.com/ - All Rights Reserved

No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing

© 2025 https://blog.aimactgrow.com/ - All Rights Reserved