> All in One 586

Ads

Tuesday, June 2, 2026

::search-text

The CSS ::search-text pseudo-element selects matching text from your browser’s “find in page” feature. For example, if you use your browser search to find “search-text” on this page, all instances of it will highlight. This pseudo-element lets us style the appearance of that highlight.

And a bonus! If there are multiple matches on the page, then ::search-text can be used with the :current pseudo-class to style the match that’s currently in focus.

You can “find in page” using the CTRL + F (for Windows) or "⌘F" (for Mac) keyboard shortcuts.

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

::search-text:current {
  background: oklch(62% 0.22 38) /* red */;
  color: white;
}

The CSS ::search-text pseudo-element is defined in the CSS Pseudo-Elements Module Level 4 specification.

Syntax

Pretty straightforward! Declare the pseudo-element and add your style rules:

<element-selector>::search-text{
  /* ... */
}

Usage

It’s typically declared by itself (::search-text), but can be appended to specific elements as well:

/* All text */
::search-text {}
html::search-text {} /* kind of redundant */
/* Specific element */
section::search-text {}
strong::search-text {}

We’re a little limited as far as what CSS properties we can declare in ::search-text. Here is what it supports:

And, yes, we can use it with custom properties, like:

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

Basic usage

With the ::search-text pseudo-element, we can style the matching text results from “Find in page”. Plus, if we want to style the currently focused matching text, then we attach the :current pseudo-class after ::search-text.

/* matches all searched text */
::search-text {
  color: green;
  background-color: white;
}
/* matches any header level 1 searched text */
h1::search-text {
  text-shadow: 12px 1px lightgrey;
  background-color: black;
  color: white;
}
/* the current searched header level 1 text */
h1::search-text:current {
  color: red;
  background: white;
}

Inheritance chain

All descendants always inherit styles applied through the highlight pseudo-elements. This way, individual properties set on highlights will cascade to all elements down the three. Take for example the following HTML:

<article>
  <h2>Highlight inheritance demo</h2>
  <p>Lorem ipsum dolor sit amet. <strong>Lorem</strong> appears again here. Another lorem appears here.
  </p>
</article>

We have an <article> container with two children: <h2> and <p>, the latter having a <strong> descendant of its own. We could style ::search-text in <article> with the following CSS, which would apply to all elements in <article>:

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

Then, override the color property for only <p> and its descendants:

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

And do the same for text-decoration on the <strong> element:

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

When you search for “lorem”, the background of the first instance (inside <p> but outside <strong>) will inherit both the background and text-decoration values from <article>, while overriding its color value with its own orange.

Onto <strong>‘s “lorem” text, it will inherit the properties we set in its parent <p> and grandparent <article. So the color and background values are inherited directly from its parent, and since they haven’t been overridden, they stay. While we override the text-decoration value to line-through.

The key takeaway from this example is that properties for highlight elements are also individually inherited and overridden.

Targeting a text

In the demo below, we set text-decoration to underline to give any searched text a blue underline. This way, we can customize matching text while also leaving the default background color, which prevents people from getting confused about what’s going on.

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

Using :current

Using ::search-text with :current, we can style the currently focused match. For example, below we apply a light orange hue text decoration color with 0.3em thickness to the currently matched searched text:

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

Some accessibility notes

For WCAG’s contrast standards, you need a contrast ratio of at least 4.5:1 between the text and background. Another piece of advice is not to change the search colors too much. In fact, this feature should be used sparingly since it may cause issues for users with cognitive issues, and as a core part of the browser, it can be generally confusing. My personal advice is to stick to only text-decoration and its associated properties since they are more subtle than the rest.

There’s also :past and :future

The :past and :future pseudo-classes are supposed to match the element entirely prior and entirely after a :current element, respectively.

However, the specification says:

The :past and :future pseudo-classes are reserved for analogous use in the future. Any unsupported combination of these pseudo-classes with ::search-text must be treated as invalid

Meaning, you can’t use :past:future or any other pseudo-class with the ::search-text pseudo-element. If your browser somehow works with them, kindly report the unexpected behavior by opening an issue with them.

Specification

The CSS ::search-text pseudo-element is defined in the CSS Pseudo-Elements Module Level 4 specification. This is still being tested and improved upon.

Browser support

Very wide support:


::search-text originally handwritten and published with love on CSS-Tricks. You should really get the newsletter as well.



from CSS-Tricks https://ift.tt/xstnblw
via IFTTT

Monday, June 1, 2026

Partly Cloudy today!



With a high of F and a low of 53F. Currently, it's 60F and Clear outside.

Current wind speeds: 17 from the East

Pollen: 3

Sunrise: June 1, 2026 at 05:27PM

Sunset: June 2, 2026 at 08:12AM

UV index: 0

Humidity: 75%

via https://ift.tt/2RTg1Wx

June 2, 2026 at 10:02AM

Astro Markdown Component Utility for Any Framework

In the previous article, I spoke about the why and how to use a Markdown component in Astro.

Here, we’re going to expand on that and help you use Markdown everywhere — regardless of the framework you use. So, this works for React, Vue, and Svelte.

The entire process hinges on the Markdown utility I’ve built for Splendid Labz.

Why This Utility?

I hit a snag when using most Markdown libraries. I naturally write Markdown content like this:

<div>
  <div>
    <!-- prettier-ignore -->
    <Markdown>
      This is a paragraph

      This is a second paragraph
    </Markdown>
  </div>
</div>

But since most markdown libraries don’t account for whitespace indentation, they create an output with <pre> and <code> tags.

This is because Markdown treats the indentation beyond four spaces as a code block:

<div>
  <div>
    <pre><code>  This is a paragraph

      This is a second paragraph
    </code></pre>
  </div>
</div>

So you’re forced to strip all indentation and write it like this instead:

<div>
  <div>
    <!-- prettier-ignore -->
    <Markdown>
  This is a paragraph

  This is a second paragraph
    </Markdown>
  </div>
</div>

That’s hard to read and annoying to maintain.

My Markdown utility handles this whitespace issue and generates the correct HTML regardless of how your code is indented:

<div>
  <div>
    <p>This is a paragraph</p>
    <p>This is a second paragraph</p>
  </div>
</div>

Using This in Your Framework

It’s easy. You have to pass the Markdown text into the utility. If inline is true, then markdown will return an output without paragraph tags.

Here’s an example with Astro.

---
import { markdown } from '@splendidlabz/utils'
const { inline = false, content } = Astro.props
const slotContent = await Astro.slots.render('default')

// Process content
const html = markdown(content || slotContent, { inline })
---

<Fragment set:html={html} />

You can then use it like this:

<Markdown>
   <!-- Your content here -->
</Markdown>

Here’s another example for Svelte.

Svelte cannot read dynamic content from slots, so we can only pass it through a prop.

<script>
  import { markdown } from '@splendidlabz/utils'
  const { content, inline = false } = $props()
  const html = markdown(content, { inline })
</script>

<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html html}

And you can use it like this:

<Markdown content=`
  ### This is a header

  This is a paragraph
`/>

It’s rather simple to build the same for React and Vue so I’d leave that up to you.

Taking it Further

I’ve been building for the web — long enough to experience the frustration of doing the same things over and over again.

So I consolidated everything I use into a few simple libraries — like Splendid Utils, and a few others for layouts, Astro and Svelte components.

I write about all of them on my blog. Come by if you’re interested in better DX as you build your sites and apps!


Astro Markdown Component Utility for Any Framework originally handwritten and published with love on CSS-Tricks. You should really get the newsletter as well.



from CSS-Tricks https://ift.tt/sdfOP15
via IFTTT

Sunday, May 31, 2026

Partly Cloudy today!



With a high of F and a low of 53F. Currently, it's 64F and Clear outside.

Current wind speeds: 9 from the East

Pollen: 3

Sunrise: May 31, 2026 at 05:27PM

Sunset: June 1, 2026 at 08:11AM

UV index: 0

Humidity: 39%

via https://ift.tt/6nz0sZe

June 1, 2026 at 10:02AM

Saturday, May 30, 2026

Clear today!



With a high of F and a low of 46F. Currently, it's 58F and Clear outside.

Current wind speeds: 11 from the North

Pollen: 3

Sunrise: May 30, 2026 at 05:28PM

Sunset: May 31, 2026 at 08:10AM

UV index: 0

Humidity: 59%

via https://ift.tt/Bc36XHZ

May 31, 2026 at 10:02AM

Friday, May 29, 2026

Thunderstorms Early today!



With a high of F and a low of 49F. Currently, it's 59F and Showers in the Vicinity outside.

Current wind speeds: 8 from the Southeast

Pollen: 3

Sunrise: May 29, 2026 at 05:28PM

Sunset: May 30, 2026 at 08:10AM

UV index: 0

Humidity: 72%

via https://ift.tt/9LjsSF4

May 30, 2026 at 10:02AM

What’s !important #12: Safari Testing, ::checkmark, HTML Anchor Positioning, and More

What’s !important #12 talks about the old (testing in Safari when you don’t have Safari), the new (::checkmark), the in-between (anchor positioning but with HTML), and more.

Buckle up!

Testing in Safari when you don’t have Safari

A Safari browser window on macOS showing an About Safari dialogue box with a translucent red and orange noise filter.
Source: Frontend Masters

Safari is the second most popular web browser, but is only available to Apple users. Fair enough. I mean, Apple are heavily invested in making Safari a proprietary browser that’s deeply integrated with Apple’s software and hardware. However, this makes testing websites in Safari a bit of a pain. Declan Chidlow explained what our options are in regards to testing in Safari when you don’t have Safari.

A first look at ::checkmark

Sunkanmi Fafowora gave us our first look at the ::checkmark pseudo-element, which solves the age-old problem of not (really) being able to style checkmarks. Note that this also targets the checked state indicator of radios and selects, not just checkboxes!

Different shape styles with border-shape + shape()

Temani Afif pointed out that we can create more shape styles when combining border-shape with the shape() function (compared to clip-path), and, easily switch between them.

Three variations of a wavy shape rendered in red, showing an outline version, a solid filled version, and a cutout version inside a solid red square.
Source: CSS Tip

A concise guide to sibling-index() and sibling-count()

Durgesh Pawar did a deep dive on sibling-index() and sibling-count(), showing us all of the cool things that we can do with these almost-Baseline CSS functions.

Also, don’t miss Durgesh’s two-part series about View Transition gotchas right here on CSS-Tricks.

Managing anchor associations with data attributes and advanced attr()

This one’s actually from me! Disappointed to hear that the anchor attribute has been dropped, which would’ve provided a way of managing anchor associations using HTML, I demonstrated my alternative technique that involves managing anchor associations with data attributes and advanced attr().

I won’t spoiler the CSS, but here are the different HTML syntaxes that I explored:

<!-- anchor attribute -->
<div anchor="anchorA">Boat A</div>
<div id="anchorA">Anchor A</div>

<!-- Data attributes with custom ident (requires attr()) -->
<div data-boat="--anchorA">Boat A</div>
<div data-anchor="--anchorA">Anchor A</div>

<!-- Data attributes (requires attr() and ident()) -->
<div data-boat="anchorA">Boat A</div>
<div data-anchor="anchorA">Anchor A</div>

Take the State of CSS 2026 survey

The official graphic for the State of CSS 2026 survey, featuring a stylized CSS logo inside a pink and purple diamond emblem against a dark background.

It’s that time of the year again!

I love these “state of” surveys (especially the State of CSS 2026 survey, but I’m sure you know that already). This year feels different though, and I’m not the only one that’s noticed.

From the opening crawl:

Take a deep breath. Calm down. It’s ok if you don’t know every single new CSS property. The truth is, very few of us do.

Look, one of this survey’s goals has always been to help keep developers up to date on the latest and greatest CSS improvements. But the downside is that all this progress can sometimes feel overwhelming.

That’s why this year we made a conscious effort to reduce the number of features covered in the survey, focusing instead on the ones that matter most.

I totally get it. It’s becoming more and more difficult to keep up with CSS. My “things to check out” list just keeps getting longer! That being said, there’s never been a more exciting time to be a fan of CSS. That feeling when you learn a new feature and then two more get shipped, is overwhelming but in the best way possible.

But still, time doesn’t grow on trees, so we have to figure out which features to invest in, and that’s what these “state of” surveys are all about. And they’re going hard this year, really zeroing in on the most important ones.

But, if you have an appetite for all things CSS, I hear there’s a great blog for that!

New web platform features

Quality over quantity, I guess!

Until next time.


What’s !important #12: Safari Testing, ::checkmark, HTML Anchor Positioning, and More originally handwritten and published with love on CSS-Tricks. You should really get the newsletter as well.



from CSS-Tricks https://ift.tt/2X3kDC9
via IFTTT

::search-text

The CSS  ::search-text  pseudo-element selects matching text from your browser’s “find in page” feature. For example, if you use your brows...