Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Components

Free

Highlight for Svelte

Highlight search terms within text.

Framework
UI library
Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
Use email insteadNo credit card

Usage

<script lang="ts">
import { Highlight } from "@/components/ui/highlight";
</script>
<p class="text-base text-foreground leading-relaxed">
  <Highlight
    query="component"
    text="shadcn.io is a component library for building accessible web applications."
  />
</p>

Demos

Custom Style

Preview width

Multiple

Preview width

Search Query

Preview width

Squiggle

Preview width

API Reference

Highlight

data-slot="highlight"

PropType
querystring | string[]

The query to highlight in the text.

Type
string | string[]
textstring

The text to highlight.

exactMatch?boolean

Whether to match whole words only.

ignoreCase?boolean

Whether to ignore case while matching.

matchAll?boolean

Whether to match multiple instances of the query.

asChild?Snippet<[PropsFn]>

Render your own element: a snippet that gets the part's props to spread on it.

Type
Snippet<[PropsFn]>
class?string

Merged with the part's classes.

useHighlight

PropType
querystring | string[]

The query to highlight in the text.

Type
string | string[]
textstring

The text to highlight.

exactMatch?boolean

Whether to match whole words only.

ignoreCase?boolean

Whether to ignore case while matching.

matchAll?boolean

Whether to match multiple instances of the query.