Highlight
shadcn-htmx/highlightFreeComponent
Semantic marker that wraps the words matching a search query in a native <mark>, the HTML element for text relevant to the user's current activity. Rendered entirely on the server, styled with theme tokens, zero client JS — drop it inside the fragment htmx swaps into a results list.
Live preview
live · rendered by the registry
Rendered by shadcn-htmx on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shadcn-htmx.productdevbook.com/r/highlight.jsonSource
1/** @jsxImportSource hono/jsx */2import type { Child } from "hono/jsx"3import { cn, type ClassValue } from "@/registry/lib/cn"45// Highlight — shadcn-htmx, htmx v4 + Tailwind v4.6//7// Semantic marker for text that is relevant to the user's current activity —8// the canonical case is the words that matched a search query. It is a thin,9// server-rendered wrapper around the native <mark> element; the server splits10// a string on the query terms and wraps each match in a styled <mark>.11//12// Source of truth:13// - <mark> semantics + the "search results" use case + the screen-reader14// announcement note:15// repos/mdn/files/en-us/web/html/reference/elements/mark/index.md16// ("`<mark>` indicates a portion of the document's content which is likely17// to be relevant to the user's current activity … the words that matched18// a search operation." MDN also notes that `<mark>` is NOT announced by19// default — which is correct here: a highlighted search match is a visual20// affordance, not extra content to read out. Do not abuse the21// ::before/::after announcement trick on a results list.)22// - Don't use <mark> for syntax highlighting — use <span> (MDN, same file).23// This component is strictly for relevance, never decoration.24//25// htmx: nothing of its own. The component just produces the marked-up HTML;26// the server renders it inside whatever fragment htmx swaps in (e.g. the27// <tr> rows returned to an Active Search `hx-target`). It forwards hx-*/data-*/28// aria-* via {...rest} so a single highlighted term can also be a swap hook.29// Verified there is no <mark>-specific htmx attribute:30// repos/htmx/www/reference.md31//32// JS budget: none. Pure SSR + one CSS rule's worth of utility classes. The33// native <mark> default is a yellow background; we reset it to theme tokens so34// it reads on brand in light and dark and never clashes with selection colours.35//36// Accessibility:37// - Keep highlighting to genuine matches. WCAG 1.4.1 (Use of Color): the38// match must not rely on the tint alone to be perceivable — <mark> is a39// real semantic element, and the bold weight + rounded chip give a40// non-colour cue, so a match survives in a high-contrast / forced-colours41// theme.42// - Case-insensitive matching by default; the ORIGINAL casing of the source43// text is preserved in the output (we slice the source, never the query).4445// … truncated
More from shadcn-htmx
All 83 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | shadcn-htmx | Components | Free | no deps | |
| Active Searchactive-search | shadcn-htmx | Components | Free | no deps | |
| Alertalert | shadcn-htmx | Components | Free | no deps | |
| Alert Dialogalert-dialog | shadcn-htmx | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | shadcn-htmx | Components | Free | no deps | |
| Auto Gridauto-grid | shadcn-htmx | Components | Free | no deps | |
| Autocompleteautocomplete | shadcn-htmx | Components | Free | no deps | |
| Autosize Textareaautosize-textarea | shadcn-htmx | Components | Free | no deps |
