---
title: Highlight
description: "`Highlight` is a component that highlights specified strings within text. By default, it renders a `p` element."
links:
- source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/highlight
- storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-highlight--basic
---
# Highlight
`Highlight` is a component that highlights specified strings within text. By default, it renders a `p` element.
```tsx
わかんないよ…。わっかんないよ! ジュー君の言ってることはひとつもわかんないよ!
ジュー君がいいって言ってるもの、何がいいのかわかんないよ!
わかんない!私にはわかんないの!
ブラッディって何がカッコイイの?血なんて嫌だよ!痛いだけだよ!
狂うのどこがカッコイイの?クレイジーのどこがいいのかわかんない!
```
## Usage
```tsx
import { Highlight } from "@yamada-ui/react"
```
```tsx
import { Highlight } from "@/components/ui"
```
```tsx
import { Highlight } from "@workspaces/ui"
```
```tsx
```
### Change Variant
```tsx
{(variant, index) => (
わかんないよ…。わっかんないよ!
ジュー君の言ってることはひとつもわかんないよ!
ジュー君がいいって言ってるもの、何がいいのかわかんないよ!
わかんない!私にはわかんないの!
ブラッディって何がカッコイイの?血なんて嫌だよ!痛いだけだよ!
狂うのどこがカッコイイの?クレイジーのどこがいいのかわかんない!
)}
```
### Change Color Scheme
```tsx
{(colorScheme, index) => (
わかんないよ…。わっかんないよ!
ジュー君の言ってることはひとつもわかんないよ!
ジュー君がいいって言ってるもの、何がいいのかわかんないよ!
わかんない!私にはわかんないの!
ブラッディって何がカッコイイの?血なんて嫌だよ!痛いだけだよ!
狂うのどこがカッコイイの?クレイジーのどこがいいのかわかんない!
)}
```
### Specify Multiple
```tsx
わかんないよ…。わっかんないよ! ジュー君の言ってることはひとつもわかんないよ!
ジュー君がいいって言ってるもの、何がいいのかわかんないよ!
わかんない!私にはわかんないの!
ブラッディって何がカッコイイの?血なんて嫌だよ!痛いだけだよ!
狂うのどこがカッコイイの?クレイジーのどこがいいのかわかんない!
```
### Style the Highlight
```tsx
わかんないよ…。わっかんないよ! ジュー君の言ってることはひとつもわかんないよ!
ジュー君がいいって言ってるもの、何がいいのかわかんないよ!
わかんない!私にはわかんないの!
ブラッディって何がカッコイイの?血なんて嫌だよ!痛いだけだよ!
狂うのどこがカッコイイの?クレイジーのどこがいいのかわかんない!
```
### Use Fragments
By default, `Highlight` renders a `p` element. By setting `fragment`, `highlight` will use [Fragment](https://react.dev/reference/react/Fragment).
```tsx
わかんないよ…。わっかんないよ!
ジュー君の言ってることはひとつもわかんないよ!
ジュー君がいいって言ってるもの、何がいいのかわかんないよ!
わかんない!私にはわかんないの!
ブラッディって何がカッコイイの?血なんて嫌だよ!痛いだけだよ!
狂うのどこがカッコイイの?クレイジーのどこがいいのかわかんない!
```
### Customize the Rendered Element
By using `useHighlight`, you can customize multiple elements and their styles.
```tsx
const chunks = useHighlight({
query: ["わかんない", "ジュー君"],
text: " わかんないよ…。わっかんないよ! ジュー君の言ってることはひとつもわかんないよ! ジュー君がいいって言ってるもの、何がいいのかわかんないよ! わかんない!私にはわかんないの! ブラッディって何がカッコイイの?血なんて嫌だよ!痛いだけだよ! 狂うのどこがカッコイイの?クレイジーのどこがいいのかわかんない!",
})
return (
{chunks.map(({ match, text }, index) =>
match ? (
text === "わかんない" ? (
{text}
) : (
{text}
)
) : (
text
),
)}
)
```
## Props
| Prop | Default | Type | Description |
| ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
| `as` | - | `As` | The HTML element to render. |
| `asChild` | - | `boolean` | Merges its props onto its immediate child. |
| `css` | - | `CSSObject \| CSSObject[]` | The CSS object. |
| `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. |
| `children` | - | `string` | The text used for searching. |
| `query` | - | `string \| string[]` | Can be a single string or an array of strings. These are the terms that are highlighted in the text. |
| `align` | - | `"-khtml-center" \| "-khtml-left" \| "-khtml-right" \| "-moz-center" \| "-moz-initial" \| "-moz-left" \| "-moz-right" \| "-webkit-center" \| "-webkit-left" \| "-webkit-match-parent" ...` | The CSS `text-align` property. |
| `casing` | - | `"-moz-initial" \| "capitalize" \| "full-size-kana" \| "full-width" \| "inherit" \| "initial" \| "lowercase" \| "math-auto" \| "none" \| "revert-layer" ...` | The CSS `text-transform` property. |
| `decoration` | - | `"-moz-initial" \| "AccentColor" \| "AccentColorText" \| "ActiveBorder" \| "ActiveCaption" \| "ActiveText" \| "aliceblue" \| "antiquewhite" \| "AppWorkspace" \| "aqua" ...` | The CSS `text-decoration` property. |
| `fragment` | `false` | `boolean` | If `true`, `Fragment` is used for rendering. |
| `markProps` | - | `MarkProps` | Properties passed to the Mark component which is used to highlight the matched terms. |
## Similar Components
- [Blockquote](https://yamada-ui.com/docs/components/blockquote.md): `Blockquote` is a component that represents a quotation. By default, it renders a `blockquote` element.
- [Code](https://yamada-ui.com/docs/components/code.md): `Code` is a component that represents a code block. By default, it renders a `code` element.
- [Em](https://yamada-ui.com/docs/components/em.md): `Em` is a component that represents emphasized text. By default, it renders a `em` element.
- [Heading](https://yamada-ui.com/docs/components/heading.md): `Heading` is a component that represents section headings. By default, it renders an `h1` element.
- [Kbd](https://yamada-ui.com/docs/components/kbd.md): `Kbd` is a component that represents keyboard input.
- [Mark](https://yamada-ui.com/docs/components/mark.md): `Mark` is a component that emphasizes a specific part of the text.
- [Text](https://yamada-ui.com/docs/components/text.md): `Text` is a component that represents a paragraph of text. By default, it renders a `p` element.
- [Link](https://yamada-ui.com/docs/components/link.md): `Link` is a component for creating hyperlinks to different web pages, locations within the same page, or other URLs.
## Uses Components & Hooks
- [Mark](https://yamada-ui.com/docs/components/mark.md): `Mark` is a component that emphasizes a specific part of the text.
- [Text](https://yamada-ui.com/docs/components/text.md): `Text` is a component that represents a paragraph of text. By default, it renders a `p` element.