Join our Discord community
Special effects

Motion Highlight

Versatile highlight component with smooth animations for interactive UI elements. Perfect for React applications requiring dynamic visual feedback with Next.js integration and TypeScript support.

Powered by

Loading component...

Installation

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

Features

  • Two rendering modes - Children mode with layoutId technique and parent mode for z-index control
  • Hover and click interactions with configurable event handling
  • Controlled and uncontrolled modes for flexible state management
  • Bounds offsetting for fine-tuning highlight positioning
  • TypeScript support with complete generic type definitions
  • AnimatePresence support with configurable exit delays

Examples

Hover Mode

Loading component...

Activate highlighting on hover instead of click for more responsive interactions.

Parent Mode

Loading component...

Use parent mode to avoid z-index issues by positioning the highlight in the container.

Card Grid

Loading component...

Create interactive card grids with smooth highlight transitions between items.

Use Cases

This free open source React component works well for:

  • Tab navigation - Highlight active tabs with smooth transitions built with Next.js
  • Menu systems - Show active menu items using TypeScript and Tailwind CSS
  • Card interfaces - Interactive grid layouts with visual feedback
  • Button groups - Toggle button states with shadcn/ui integration
  • Settings panels - Highlight selected options in configuration interfaces

API Reference

MotionHighlight

PropTypeDefaultDescription
mode"children" | "parent""children"Highlight rendering strategy
valuestring | null-Controlled active value
defaultValuestring | null-Default active value (uncontrolled)
onValueChange(value: string | null) => void-Callback when value changes
hoverbooleanfalseActivate on hover instead of click
disabledbooleanfalseDisable all interactions
enabledbooleantrueEnable/disable highlighting
controlledItemsbooleanfalseUse MotionHighlightItem manually
transitionTransition{ type: 'spring', stiffness: 350, damping: 35 }Motion transition config
exitDelaynumber0.2Delay before highlight exits
classNamestring-Highlight element classes
itemsClassNamestring-Default item wrapper classes
containerClassNamestring-Container classes (parent mode)
boundsOffsetPartial<Bounds>-Positioning offset adjustments
forceUpdateBoundsboolean-Continuously update bounds

MotionHighlightItem

PropTypeDefaultDescription
valuestring-Unique identifier for the item
idstring-Alternative identifier
asChildbooleanfalseMerge props with child element
disabledboolean-Disable this specific item
activeClassNamestring-Classes when item is active
transitionTransition-Override default transition
exitDelaynumber-Override default exit delay
forceUpdateBoundsboolean-Continuously update bounds for this item

Modes

Children Mode (default):

  • Uses Motion's layoutId for smooth transitions
  • Highlight is positioned within each item
  • Better performance, recommended for most cases

Parent Mode:

  • Highlight positioned absolutely in container
  • Avoids z-index conflicts
  • Better for complex layouts with overlapping elements

Implementation Notes

  • Use data-value attribute on elements for automatic item identification
  • Parent mode calculates bounds relative to container position
  • boundsOffset useful for border/padding adjustments in parent mode
  • Children mode uses layoutId for shared element transitions
  • The component handles both mouse and keyboard interactions
  • Compatible with shadcn/ui design tokens and styling patterns