Text Hover Effect

NewMotion

Interactive typographic SVG reveal effect that traces letter strokes on mount and reveals a vibrant radial gradient mask following cursor movement.

$ pnpm dlx shadcn@latest add @byphongphan/text-hover-effect
Requires @byphongphan in components.json
text
Loading preview...

Installation

$ pnpm dlx shadcn@latest add @byphongphan/text-hover-effect
Requires @byphongphan in components.json

Anatomy

TextHoverEffect (SVG container with pure math SSR viewBox)├── <defs>│   ├── <linearGradient> (Multi-stop gradient for letter fill)│   ├── <motion.radialGradient> (Spotlight circle tracking cursor coords)│   └── <mask> (Applies radial spotlight as a stencil over text)├── <text (hidden)> (Invisible DOM element for sub-pixel bbox measuring)├── <text (outline)> (Faint stroke that fades in on hover)├── <motion.text (stroke)> (Entrance animation drawing character contours)└── <text (revealed)> (Gradient-colored fill clipped by radial mask)

Usage

import { TextHoverEffect } from "@/components/text-hover-effect"
export function HeroSection() {  return (    <div className="mx-auto h-40 w-full max-w-2xl">      <TextHoverEffect text="PORTFOLIO" />    </div>  )}

Features

  • SSR-Safe Pure-Math ViewBox: Calculates an accurate initial SVG bounding box mathematically without requiring client DOM access, preventing layout shift and hydration mismatches.
  • Isolated Multi-Instance IDs: Automatically scopes SVG gradient, filter, and mask IDs with useId(), allowing multiple independent instances on the same page without cursor conflict.
  • Dynamic Gradient Palettes: Pass custom hex color arrays to match brand guidelines, dark cyberpunk themes, or warm sunset palettes.
  • Automatic Ambient Sweep: Activate automatic={true} to continuously sweep the radial spotlight back and forth across the text during idle periods.
  • Responsive Vector Geometry: Built entirely with scalable vector graphics that seamlessly fit any container width while preserving sharp typographic contours.

Examples

Automatic Ambient Sweep

Autonomously moves the radial gradient mask across the text back and forth when idle, without requiring cursor interactions.

AUTOMATICAUTOMATICAUTOMATICAUTOMATICAUTOMATIC

Cyberpunk Neon Palette

Customize the gradient stops with electric cyan, blue, violet, and hot magenta tones.

CYBERPUNKCYBERPUNKCYBERPUNKCYBERPUNKCYBERPUNK

Sunset Palette

Warm, energetic color transitions using gold, orange, and purple hues.

SUNSETSUNSETSUNSETSUNSETSUNSET

API Reference

TextHoverEffect

Interactive typographic SVG reveal component.

PropTypeDefaultDescription
textstring—The text string to render and animate (required).
durationnumber0Cursor follow interpolation duration in seconds. Set higher for smoother lag effect.
automaticbooleanfalseWhen enabled, continuously sweeps the radial gradient across the text when idle.
strokeDurationnumber4Duration in seconds of the initial outline drawing animation on mount.
colorsstring[]["#eab308", "#ef4444", "#3b82f6", "#06b6d4", "#8b5cf6"]Custom hex or CSS color stops for the hover reveal gradient.
classNamestringundefinedAdditional CSS classes for the SVG container.

Command Palette

Quick search and commands navigation