Join our Discord Community
Text

Highlight Text

Animated text highlight component with gradient backgrounds and in-view detection. Perfect for React applications requiring text emphasis with Next.js integration and TypeScript support.

Powered by

Loading component...

Installation

npx shadcn@latest add https://www.shadcn.io/registry/highlight-text.json
npx shadcn@latest add https://www.shadcn.io/registry/highlight-text.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/highlight-text.json
bunx shadcn@latest add https://www.shadcn.io/registry/highlight-text.json

Features

  • Gradient animations with smooth background size transitions from 0% to 100% width
  • In-view detection triggers highlight animation when component enters viewport using Motion
  • Customizable transitions with configurable duration, easing, and animation timing
  • Theme-aware styling with automatic light/dark mode gradient colors and proper contrast
  • TypeScript support with complete interface definitions for all animation props
  • Performance optimized using CSS transforms for smooth 60fps highlight animations

Use Cases

This free open source React component works well for:

  • Landing pages - Highlight key phrases and call-to-action text in Next.js applications
  • Content marketing - Emphasize important points in articles using TypeScript and Tailwind CSS
  • Educational content - Draw attention to key concepts and definitions
  • Product demos - Highlight features and benefits with engaging visual effects

API Reference

HighlightText

PropTypeDefaultDescription
textstringrequiredText content to be highlighted
inViewbooleanfalseOnly animate when component enters viewport
inViewMarginstring"0px"Margin for in-view detection trigger
inViewOncebooleantrueOnly trigger in-view animation once
transitionTransition{ duration: 2, ease: 'easeInOut' }Motion transition configuration for highlight animation
classNamestring-CSS classes for custom styling and text appearance

Default Styling

  • Light mode - Blue to purple gradient (from-blue-100 to-purple-100)
  • Dark mode - Saturated blue to purple gradient (from-blue-500 to-purple-500)
  • Padding - 8px horizontal, 4px vertical for readable spacing
  • Border radius - 8px for modern, rounded appearance

Implementation Notes

  • Uses CSS backgroundSize animation for smooth highlight effect
  • Background position is set to "left center" for consistent animation start
  • Display is set to "inline" to maintain text flow within paragraphs
  • Component forwards ref for advanced use cases and external control
  • Supports all standard span HTML attributes and event handlers
  • Animation automatically cleans up on component unmount