Cómo funciona
The gradient is three times as wide as the text, clipped to the glyphs, and its position drifts back and forth with an ease-in-out, so colour flows through the letters and slows at each end instead of sliding past at a constant rate. Palettes are defined in the stylesheet with a lighter set under the dark theme. A small padding keeps descenders inside the clip, decoration-break: clone keeps the gradient whole across line breaks, and selection falls back to solid text.
Úsalo para
- One key phrase in a hero headline.
- Large figures or short labels that should feel special.
Busca otra opción cuando
- Body text or anything long: gradients make reading harder.
- More than one or two places per screen.
Uso
import { GradientText } from './GradientText.jsx'
export function Hero() {
return (
<h1>
Write it once. <GradientText palette="aurora" speed={8}>Find it forever.</GradientText>
</h1>
)
}
// Your own colours: <GradientText colors={['#0ea5e9', '#a855f7']}>…</GradientText>Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
children | ReactNode | — | The text. |
palette | 'aurora' | 'dusk' | 'ocean' | 'ink' | 'aurora' | Named palette with a lighter set for the dark theme. |
colors | string[] | — | Your own colours (two or more); the first repeats at the end so the loop is seamless. |
speed | number | 8 | Seconds for one sweep (minimum 2). |
angle | number | 100 | Gradient angle in degrees. |
animate | boolean | true | Set false for a still gradient. |
as | ElementType | 'span' | Element to render. |
Accesibilidad
- The text stays real text: selectable, translatable and read by screen readers exactly as written.
- Each palette keeps its darkest stops dark enough on light surfaces, and the dark-theme set is lighter, so large text stays above 3:1 throughout the cycle.
- Selected text turns solid for legibility; forced-colors mode shows plain text in the system colour.
- Reduced motion stops the flow and keeps a still gradient.
Movimiento
The gradient drifts across in 8s (adjustable) with an ease-in-out and reverses, so it never jumps.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
GradientText.jsxgradient-text.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.



