本文へ移動
日本語

仕組み

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.

向いている場面

  • One key phrase in a hero headline.
  • Large figures or short labels that should feel special.

向かない場面

  • Body text or anything long: gradients make reading harder.
  • More than one or two places per screen.

使い方

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>

プロパティ

プロパティ型既定値説明
childrenReactNode—The text.
palette'aurora' | 'dusk' | 'ocean' | 'ink''aurora'Named palette with a lighter set for the dark theme.
colorsstring[]—Your own colours (two or more); the first repeats at the end so the loop is seamless.
speednumber8Seconds for one sweep (minimum 2).
anglenumber100Gradient angle in degrees.
animatebooleantrueSet false for a still gradient.
asElementType'span'Element to render.

アクセシビリティ

  • 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.

モーション

The gradient drifts across in 8s (adjustable) with an ease-in-out and reverses, so it never jumps.

プロジェクトに追加

プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。

GradientText.jsxgradient-text.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

文字の動き
「モーフィング文字」は Pro に含まれます。解除するとプレビューが表示されます。
「スクランブル文字」は Pro に含まれます。解除するとプレビューが表示されます。