Skip to content

Highlight - Vant 4

Highlight

Make your text shine! Transform ordinary content into visually striking highlights that capture attention and improve readability. Perfect for search results, keywords, and important information! 🎯

💡 Intro

Spotlight your content with style! 🌟 The Highlight component intelligently identifies and emphasizes specified text content, making it perfect for search results, keyword highlighting, and drawing attention to important information. Please upgrade vant to >= v4.8.0 before using this component.

📦 Install

Get started in seconds! 🚀 Register the component globally and start highlighting text content throughout your application.

Register component globally via app.use, refer to Component Registration for more registration ways.

js
import { createApp } from'vue'; import { Highlight } from'vant'; const app = createApp(); app.use(Highlight);

🎨 Usage

Discover the power of intelligent text highlighting! ✨ From basic keyword emphasis to advanced multi-term highlighting with custom styling.

🎯 Basic Usage

Start with simple keyword highlighting! 🔍 Specify your target keywords and source text to instantly create visual emphasis.

You can specify keywords to be highlighted with keywords and source text with source-string.

html
ts
exportdefault { setup() { const text = 'Take your time and be patient. Life itself will eventually answer all those questions it once raised for you.'; const keywords = 'questions'; return { text, keywords, }; }, };

🎪 Multiple Keywords

Highlight multiple terms at once! 🌈 Perfect for complex search results and comprehensive content emphasis.

If you need to specific more than one keywords, you can pass in keywords as an array.

html
ts
exportdefault { setup() { const text = 'Take your time and be patient. Life itself will eventually answer all those questions it once raised for you.'; const keywords = ['time', 'life', 'answer']; return { text, keywords, }; }, };

🎨 Custom Class

Make it uniquely yours! ✨ Apply custom styling to highlighted text for perfect brand alignment and visual impact.

Set the highlight-class of the highlighted tag to customize the style.

html
ts
exportdefault { setup() { const text = 'Take your time and be patient. Life itself will eventually answer all those questions it once raised for you.'; const keywords = 'life'; return { text, keywords, }; }, };
css
.custom-class { color: red; }

🔧 API

Complete control at your fingertips! ⚙️ Configure every aspect of text highlighting with comprehensive props and customization options.

📋 Props

Fine-tune your highlighting experience! 🎛️ From case sensitivity to custom HTML tags, these props give you complete control over text emphasis behavior.

AttributeDescriptionTypeDefault
auto-escapeWhether to automatically escapebooleantrue
case-sensitiveIs case sensitivebooleanfalse
highlight-classClass name of the highlight elementstring-
highlight-tagHTML Tag of highlighted elementstringspan
keywordsExpected highlighted text*stringstring[]*
source-stringSource textstring-
tagHTML Tag of root elementstringdiv
unhighlight-classClass name of the unhighlight elementstring-
unhighlight-tagHTML Tag of unhighlighted elementstringspan

📝 Types

Full TypeScript support for enhanced development! 🚀 Import these types for better code completion and type safety.

The component exports the following type definitions:

ts
importtype { HighlightProps, HighlightThemeVars } from'vant';

🎨 Theming

Make it uniquely yours! 🌈 Customize every visual aspect with CSS variables for perfect brand alignment.

🎛️ CSS Variables

Transform the visual appearance! ✨ Use these CSS variables to match your brand colors and design system perfectly.

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-highlight-tag-colorvar(--van-primary-color)Color of highlighted text

Explore related components and features! 🔗 Build comprehensive text processing and search experiences with these complementary tools.

  • Search - Search input and functionality
  • Tag - Text tags and labels
  • Text- Text display and formatting
  • Cell - List-style content cells
  • List - Data lists and collections
  • Card - Content cards and containers
  • Badge - Notification badges and indicators
  • Button - Interactive buttons and actions
  • Icon - Beautiful icons and symbols
  • ConfigProvider - Global configuration
  • Advanced Usage - Advanced implementation patterns

Enterprise-level mobile solution based on Vant