---
title: "Highlight"
description: "Marks the words in a text that match a search, so people see why a result came up. It can match whole words, letter case, and words with accents."
url: https://gelatinui.com/components/highlight
markdown_url: https://gelatinui.com/components/highlight.md
access: free
install: "npx shadcn@latest add @gelatin-ui/highlight"
registry_item: https://gelatinui.com/r/highlight.json
version: "2026-11-09"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Highlight

> Marks the words in a text that match a search, so people see why a result came up. It can match whole words, letter case, and words with accents.

Page: https://gelatinui.com/components/highlight

## When to use it

Best for: Marking search terms in text or rich content, with each match wrapped in a Mark.

- Use it to show why a search result matches.
- Use `highlight` for one term or many.
- Use `ranges` when a fuzzy search or a server gives the places to mark.
- Use `wholeWord`, `caseSensitive`, `ignoreAccents`, and `locale` to change the matching.

## When not to use it

- For a phrase that you choose by hand, use a [Mark](https://gelatinui.com/components/mark.md).

## Notes for agents

- A blank search marks nothing, so an empty search field shows the content as it is.
- `ranges` takes `[start, end)` in UTF-16 units and works only with plain string `children`.
- Rich content is searched one text piece at a time, so a match does not cross two elements.
- A component that reads the shape of its children sees one child. Give it plain strings, or skip it with `data-highlight-skip`.
- For rich content with paragraphs or lists, use `render={<div />}`. A `<span>` may not hold blocks.
- It never builds a `RegExp` from the terms, so do not escape them.
- Use `tone` for every mark, and `markProps` for other props of every mark.

## Anatomy

```text
Highlight
```

## API reference

### Highlight

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `caseSensitive` | `boolean` |  | Match the exact case. Off by default: "key" also finds "Key". |
| `ignoreAccents` | `boolean` |  | Match letters with and without accents: "cafe" also finds "Café". It removes only the combining diacritical marks (U+0300 to U+036F: the accents of Latin, Greek, and Cyrillic), not the vowel signs of Devanagari or Thai, which change the word. Off by default. |
| `wholeWord` | `boolean` |  | Match only whole words: "key" finds "key" but not "Keychain". Off by default. |
| `locale` | `string` |  | The language of the text, for lowercasing (Turkish "I" → "ı") and word edges. Without it, the matcher uses the locale-free `toLowerCase`, so the server and the browser give the same marks. A tag that is not valid BCP 47 (`"en_US"`) falls back to no locale, with a warning in development, so a locale from user data cannot crash the render. |
| `children` | `ReactNode` |  | The content to search: a plain string, or rich content (nested elements). In rich content each text piece is searched on its own (see the rich-content notes on `Highlight`). |
| `highlight` | `string \| readonly string[]` | NO_TERMS | One search term or many. Blank terms are skipped, so an empty search field marks nothing. |
| `ranges` | `readonly HighlightRange[]` |  | Ranges to mark, `[start, end)` in UTF-16 units, in place of `highlight` (a fuzzy search or a server gives them). They are clamped, sorted, merged, and widened to whole characters. Plain string `children` only: in rich content the indexes have no single text to point into. |
| `tone` | `"destructive" \| "info" \| "neutral" \| "success" \| "warning"` |  | The tone of every mark. |
| `markProps` | `Omit<MarkProps, "children" \| "tone">` |  | Props for every mark: `className`, `cue`, data attributes. |
| `render` | `ReactElement` |  | The root element, in place of the `<span>`: `render={<div />}` for rich content with blocks (paragraphs, lists), which a `<span>` may not hold. It gets the props and the marked content. |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| Highlight | `highlight` |  |  |  |

## Usage

Pass the search term as `highlight`, and the text as `children`. A blank search shows the text as it is.

```tsx title="search-snippet.tsx"
import { Highlight } from "@/components/ui/highlight";

export function SearchSnippet({ query }: { query: string }) {
  return <Highlight highlight={query}>Rotate the API key every 90 days.</Highlight>;
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/highlight
```

It adds 12 registry items: 11 files, 1255 lines, and the npm packages `@base-ui/react`, `tailwind-merge`, `tailwind-variants`.

## Built on

- [Mark](https://gelatinui.com/components/mark.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Mark](https://gelatinui.com/components/mark.md)
- [Input](https://gelatinui.com/components/input.md)
- [Typography](https://gelatinui.com/components/typography.md)

## Accessibility

Each match is a native `<mark>`, so the text stays in place and in reading order.

It has no hooks and takes no focus. It renders on the server.
