Gradient Text
A flowing spectrum of color for a few words you want to make unforgettable.
COLOR OUTSIDE THE ORDINARY
Stay a little
different.
A brighter turn of phrase.
Live component. Go ahead, interact.
Accent
REACT / TYPESCRIPT
import type { CSSProperties, HTMLAttributes, ReactNode } from 'react'
import './gradient-text.css'
export interface GradientTextProps extends HTMLAttributes<HTMLSpanElement> {
children: ReactNode
/** At least two CSS colors, arranged in reading order. */
colors?: string[]
/** Duration in seconds of one color sweep. */
speed?: number
paused?: boolean
}
const defaultColors = ['#ef9b61', '#f7e6cf', '#b8a0e9', '#ef9b61']
/** Keeps its text in the document while animating only its painted color. */
export function GradientText({
children,
className = '',
colors = defaultColors,
speed = 8,
paused = false,
style,
...props
}: GradientTextProps) {
const safeColors = colors
.filter((color) => typeof color === 'string' && color.trim() && color.length <= 200 && !/[;{}<>]/.test(color))
.slice(0, 8)
const palette = safeColors.length >= 2 ? safeColors : defaultColors
const duration = Number.isFinite(speed) ? Math.min(180, Math.max(1, speed)) : 8
return (
<span
{...props}
className={`ac-gradient-text ${className}`.trim()}
data-paused={paused || undefined}
style={{
'--ac-gradient-text-colors': palette.join(', '),
'--ac-gradient-text-speed': `${duration}s`,
...style,
} as CSSProperties}
>
{children}
</span>
)
}
01
Installation
Run this in your shadcn-configured React project. The component and stylesheet are added together.
TERMINAL
npx shadcn@latest add http://localhost:5173/r/gradient-text.jsonThis command uses the current site address. For localhost, keep this preview running on the same computer. Files follow your configured components alias.
02
Usage
Import the component and make the details your own.
TypeScript
import { GradientText } from '@/components/anticraft/GradientText';
export function Example() {
return <GradientText>Stay a little different.</GradientText>;
}03
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | Required | Text or inline content receiving the gradient. |
colors | string[] | Orange, cream, violet, orange | Two to eight CSS colors. Defaults to #ef9b61, #f7e6cf, #b8a0e9, #ef9b61. |
speed | number | 8 | The gradient animation duration in seconds, clamped between 1 and 180. |
paused | boolean | false | Pauses the gradient animation. |
className | string | '' | Additional classes. Native span attributes and inline styles are supported. |
04
Motion & accessibility
Considered by default.
The gradient stops moving when reduced motion is preferred.
Use semantic content and meaningful labels in your composition. Check contrast and keyboard behavior with your own styles and content.