Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Text

Pro

Text Hover Effect for React

Outlined text that draws itself in, then lights up in a gradient under the pointer. For React with Base UI, when a display word should glow where you look.

Framework

Text Hover Effect draws a word as a thin outline, tracing each letter in as the page loads, then lights the outline in colour where the pointer goes: a soft round light follows the pointer and turns the outline under it into a gradient, like a torch passing over neon tubing. When the pointer leaves, the light fades and the outline stays.

Use it for one big display word: a brand, a hero, a section title. To flood the outline with a solid fill, use Outline Text; for tubes that glow on their own, Neon Text; to light plain text, Spotlight Text. It's SVG text in your own font: a CSS keyframe animation of the outline's dashes draws it in, and the coloured copy is masked by a soft circle whose centre is two registered CSS properties that each move of the pointer writes, with no animation library. It sets one line: SVG text doesn't wrap.

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Usage

import { TextHoverEffect } from "@/components/ui/text-hover-effect";
<h2>
  <TextHoverEffect text="Electric" />
</h2>

Demos

Colors

colors are the colours the outline lights up in, any CSS colours, including your theme's variables, spread from the start of the word to its end. By default yellow, red, blue, cyan and violet.

Preview width

Inside a link, keyboard focus lights the whole word, since a keyboard can't point at part of it.

Preview width

Accessibility

Screen readers read the word once, from a visually hidden copy; the drawing is hidden from them. The outline is there whether or not the pointer is, so the word always reads; keyboard focus on a link around it lights the whole word, and on a touch screen a touch lights the spot under the finger. The outline is the text's colour at reduced strength, which reads well at display sizes; give it a heavy weight. With reduced motion the outline is there from the start and the light follows the pointer without gliding.

FAQ

Which font does it use?

Yours: SVG text takes the font, size, weight and letter spacing of the text around it. Heavy weights suit it best. Only the outer half of each outline is shown, so the overlapping shapes inside a variable font's letters, which a plain outline draws as stray lines, never show.

Can the text wrap onto two lines?

No: SVG text stays on one line, so keep it to a word or two and size it for small screens. For outlined text that wraps, use Outline Text.

How do I change or replay the drawing?

duration is how long the outline takes to draw itself in, 3000 ms by default. It draws once, when the text first appears; give it a new key and React renders it fresh, so it draws again.

How big is the light?

Its radius is the text's size by default, so it lights two or three letters at a time; pass radius in pixels, or set --text-hover-effect-radius in any unit, for a wider or narrower light.

How does the light follow the pointer?

On each move over the word, the pointer's place is written into two CSS variables, --text-hover-effect-x and --text-hover-effect-y, the centre of the circle in the coloured copy's mask. They're registered as lengths, so a transition eases the light after the pointer; nothing re-renders.

What happens with reduced motion?

The outline doesn't draw itself in: it's there from the start. The light still answers the pointer, without gliding after it.

API Reference

TextHoverEffect

<span> data-slot="text-hover-effect"

PropType
textstring

The text, on one line.

colors?string[]

The colours the outline lights up in under the pointer, any CSS colours, from the start of the text to its end. By default yellow, red, blue, cyan and violet.

Default
DEFAULT_COLORS
duration?number

How long the outline takes to draw itself in, in milliseconds.

Default
3000
radius?number

The light's radius, in pixels. By default the text's size (1em), so it scales with the text.

render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Forwarded to the part.

CSS variableType
--text-hover-effect-durationstring

How long the outline takes to draw itself in (3s).

--text-hover-effect-radiusstring

The light's radius (1em).

--text-hover-effect-widthstring

The outline's width (max(1px, 0.02em)).

  • Pro

    Outline Text

    Decorative

    Flood the outline with a solid fill

  • Pro

    Neon Text

    Decorative

    Tubes that glow on their own

  • Every detail deserves the spotlight

    Pro

    Spotlight Text

    Interactive

    Light on plain text instead

  • Gradient Text

    Decorative

    A gradient that flows by itself

  • Pro

    Paint Text

    Interactive

    Brush colour on, it fades back

  • Pro

    Xray Text

    Interactive

    A hidden message under the pointer

All 97 text effects