Highlight

A utility component that automatically highlights matching text patterns within content, useful for search results and text emphasis.

Anatomy

<script>
  import { Highlight } from "@saas-ui/svelte/typography/highlight";
</script>

<!-- Basic highlight -->
<Highlight
  query="spotlight"
  text="With the Highlight component, you can spotlight words."
/>

<!-- Multiple queries -->
<Highlight
  query={["hello", "world"]}
  text="Hello world, hello everyone!"
/>

<!-- Case insensitive -->
<Highlight
  query="react"
  text="React is a library for building React apps"
  ignoreCase
/>

Examples

Basic Accessibility

Basic highlight with default styling for emphasizing matching text patterns.

Custom Style Accessibility

Use the variant and colour props to customize the highlight appearance.

Mark Class Accessibility

Use markClass to apply custom CSS classes to the highlighted text for advanced styling.

Multiple Accessibility

Highlight multiple words by passing an array to the query prop.

Search Query Accessibility

Use ignoreCase for case-insensitive search highlighting, ideal for search results.

Props

Prop Type Default Description
query text - -
text text - -
ignoreCase boolean false -
matchAll boolean true -
variant subtle | solid | text | plain subtle -
colour accent | gray | zinc | neutral | stone | slate | red | orange | amber | yellow | lime | green | emerald | teal | cyan | sky | blue | indigo | violet | purple | fuchsia | pink | rose gray The colour theme of the component.
markClass text - Additional CSS classes to apply to the highlighted text
class text - Additional CSS classes to apply.