# Highlight search matches without touching the DOM

DevFeed: [Highlight search matches without touching the DOM](<https://devfeed.tech/articles/highlight-search-matches-without-touching-the-dom-98972.md>)

Original publisher: [Read original article](<https://markodenic.tech/highlight-search-matches-without-touching-the-dom/>)

Author: Marko

Published: 2026-10-24T13:38:02Z

Content type: tutorial

Language: en

Sources: [Marko Denic Tech](<https://devfeed.tech/sources/marko-denic-tech.md>)

Topics: [custom highlight api](<https://devfeed.tech/topics/custom-highlight-api.md>), [Front end](<https://devfeed.tech/topics/frontend.md>), [CSS](<https://devfeed.tech/topics/css.md>), [Highlight.js](<https://devfeed.tech/topics/highlightjs.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [blog-for-developers](<https://devfeed.tech/tags/blog-for-developers.md>), [build-faster](<https://devfeed.tech/tags/build-faster.md>), [code-productivity](<https://devfeed.tech/tags/code-productivity.md>), [code-smarter](<https://devfeed.tech/tags/code-smarter.md>), [content-monetization](<https://devfeed.tech/tags/content-monetization.md>), [css](<https://devfeed.tech/tags/css.md>), [css-animation](<https://devfeed.tech/tags/css-animation.md>), [css-performance](<https://devfeed.tech/tags/css-performance.md>), [custom-highlight-api](<https://devfeed.tech/tags/custom-highlight-api.md>), [developer-growth](<https://devfeed.tech/tags/developer-growth.md>), [developer-resources](<https://devfeed.tech/tags/developer-resources.md>), [email-newsletter-for-coders](<https://devfeed.tech/tags/email-newsletter-for-coders.md>), [front-end-development](<https://devfeed.tech/tags/front-end-development.md>), [github-profile-automation](<https://devfeed.tech/tags/github-profile-automation.md>), [html-tips](<https://devfeed.tech/tags/html-tips.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [javascript-tricks](<https://devfeed.tech/tags/javascript-tricks.md>), [learn-to-code](<https://devfeed.tech/tags/learn-to-code.md>), [responsive-design-tips](<https://devfeed.tech/tags/responsive-design-tips.md>), [search](<https://devfeed.tech/tags/search.md>), [ui](<https://devfeed.tech/tags/ui.md>), [web-dev-newsletter](<https://devfeed.tech/tags/web-dev-newsletter.md>), [web-development](<https://devfeed.tech/tags/web-development.md>), [web-development-tips](<https://devfeed.tech/tags/web-development-tips.md>), [weekly-dev-tips](<https://devfeed.tech/tags/weekly-dev-tips.md>), [workflow-optimization](<https://devfeed.tech/tags/workflow-optimization.md>)

## AI overview

The CSS Custom Highlight API can mark search matches without changing page elements: walk the content's text nodes, create a `Range` for each match, register them in a `Highlight` with `CSS.highlights.set`, and style the group with `::highlight(search)`. Replacing the named highlight on each input clears old matches; a second, higher-priority highlight can mark the current match and scroll it into view. The excerpt says current Chrome, Edge, Safari, and Firefox support the API, but recommends checking `CSS.highlights`; highlights are paint only, so screen readers need a separate result-count announcement. Matches spanning multiple text nodes are missed, and large pages may need debouncing.

## Source excerpt

Stop wrapping search matches in mark tags. The CSS Custom Highlight API paints every match without adding a single element to your page.