YL

TEXT EFFECT

流动渐变文字Animated Gradient Text

渐变色带在文字内部横向流动。Magic UI 的 animated-gradient-text / aurora-text 都是它的变体。

中英对照

中文
流动渐变文字
英文
Animated Gradient Text
别名
Gradient Text、Shimmer Text、Iridescent Text
一句话
渐变色带在文字内部横向流动。Magic UI 的 animated-gradient-text / aurora-text 都是它的变体。

效果预览

Gradient

常见变体

暗色主题版Gradient Text on Dark

深色背景上改用浅色系渐变,每一段都保持很高的对比度。

持续流动 + 暂停Looping Gradient with Pause

产品名需要一直流动时的写法:无限循环,但必须能停下来。

适合用在哪

品牌主标、AI 产品名、强调性的关键词。整页建议不超过两处,否则会互相抢注意力。

不适合:正文、导航、按钮文字和小于 24px 的字:渐变中较浅的一段会让局部笔画对比度下降,字越小越明显;同一页已有两处以上渐变或发光元素时也不要再加,几处同时流动会互相抢注意力。

和相近模式的区别

霓虹灯管文字Neon Text

霓虹文字只在深色背景上成立:文字本身是实心浅色,光晕靠字形外的多层 text-shadow;流动渐变文字没有光晕,颜色来自裁切成字形的背景渐变,深浅主题都能用,但要逐段检查渐变每一处颜色与背景的对比度。浅色页面的品牌强调用渐变,夜间、活动、游戏主题的招牌字用霓虹。

容易踩的坑

  • 渐变中浅色段在白底上对比度低于 3:1,标题局部会「消失」。
  • background-clip:text 不支持时未设回退色,文字变成透明不可见。
  • 选中文本时透明文字配渐变背景,选区高亮会显示异常。

设计提示词 · Prompt

流动渐变文字(Animated Gradient Text):文本设 background:linear-gradient(90deg, 主色, 高亮色, 次色, 主色) 并把 background-size 设为 200% 100%;用 -webkit-background-clip:text(加标准 background-clip:text)与 color:transparent 让文字成为渐变遮罩。动画只改 background-position 从 0% 到 200%(正好错开一整张渐变,首尾帧一致,循环不跳),线性 4.2s 播放一次;需要持续流动时必须提供可见的暂停按钮。-webkit-background-clip 与 background-clip 必须写在 background 简写之后,透明文字放进 @supports,强制颜色模式下改为 color:CanvasText 并去掉背景。字号 40-72px、字重 800、字距 -0.04em。为确保浅色主题下可读,渐变两端色值亮度差异不要太大。
Animated Gradient Text: give the text background:linear-gradient(90deg, primary color, highlight color, secondary color, primary color) and set background-size to 200% 100%; use -webkit-background-clip:text (plus the standard background-clip:text) with color:transparent so the text becomes a gradient mask. The animation only changes background-position from 0% to 200% (exactly one full gradient tile, so the first and last frames match and the loop does not jump), linear 4.2s, played once; a continuously flowing version needs a visible pause button. Write -webkit-background-clip and background-clip after the background shorthand, wrap the transparent text color in @supports, and under forced-colors switch to color:CanvasText with no background. Font size 40-72px, font weight 800, letter-spacing -0.04em. To keep it readable on light themes, avoid too large a luminance difference between the two ends of the gradient.

可复制 CSS

自包含的最小实现,粘贴到空白页面即可生效;类名可以按项目规范改名。

/* <h1 class="grad-text">Gradient</h1> */
.grad-text {
  margin: 0;
  color: #4f46e5;
  font: 800 clamp(40px, 6vw, 72px)/1.1 system-ui, sans-serif;
  letter-spacing: -.04em;
}
/* 不支持把背景裁切成文字时,保留上面的实色 */
@supports (background-clip: text) or (-webkit-background-clip: text) {
  .grad-text {
    background: linear-gradient(90deg, #4f46e5, #c026d3, #0e7490, #4f46e5);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: grad-flow 4.2s linear 1;
  }
}
/* 首尾同色、尺寸 200%、位移 0% → 200%,正好错开一整张渐变,首尾帧完全相同 */
@keyframes grad-flow {
  from { background-position: 0% 0; }
  to { background-position: 200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .grad-text { animation: none; }
}
@media (forced-colors: active) {
  .grad-text {
    background: none;
    color: CanvasText;
    animation: none;
  }
}

演示 HTML 结构

<div class="s d-center">
  <div class="tx-grad">Gradient</div>
</div>

无障碍与性能

无障碍

  • 按渐变里每一种颜色分别计算对比度:#4f46e5、#c026d3、#0e7490 对白底约为 6.3:1、4.7:1、5.4:1,都超过 4.5:1;大号文字的要求是 3:1,但渐变的过渡段会出现两色之间的中间色,留出余量更稳。
  • 强制颜色模式(Windows 高对比度)下,显式去掉背景渐变、把文字改为系统文字色 CanvasText,并停止动画,不依赖各浏览器对透明文字的默认处理。
  • 只播放一遍 4.2 秒,低于 SC 2.2.2 的 5 秒;prefers-reduced-motion: reduce 时停在静态渐变,文字始终可见。

性能

  • background-position 动画不能交给合成线程,每帧都要重绘文字区域,这是本条的例外;面积只有一行标题,只播一遍,代价可以接受,循环版整页只放一处。

常见问题

流动渐变文字的英文是什么?

流动渐变文字的英文是 Animated Gradient Text。常见英文别名还包括 Gradient Text、Shimmer Text、Iridescent Text。

Animated Gradient Text 的中文是什么?

Animated Gradient Text 的中文是「流动渐变文字」。渐变色带在文字内部横向流动。Magic UI 的 animated-gradient-text / aurora-text 都是它的变体。

流动渐变为什么每循环一次就跳一下?

背景位移的终点没有正好错开一整张渐变。background-position 的百分比按「(容器宽 − 背景宽) × 百分比」换算:background-size 为 200% 时,位移 0% → 200% 等于向左移动 2 倍容器宽,正好是一整张背景,首尾帧相同(在 Chromium 中首尾帧逐像素一致)。常见的错误写法是 280% 尺寸配 0 → -280% 位移:换算后移动约 5.04 倍容器宽,不是背景宽 2.8 倍的整数倍,循环点会跳(首尾帧不同)。渐变本身也要首尾同色,平铺的接缝才看不出来。

-webkit-background-clip 和 background-clip 两行都要写吗?

都写,带前缀的在前。各浏览器支持无前缀 background-clip: text 的时间不同,两行一起写覆盖最全。两行都要写在 background 简写之后:background 简写会把 background-clip 重置为默认的 border-box,写在前面的裁切会被覆盖,文字变成一块渐变色矩形。透明文字要放进 @supports 里,不支持时保留实色。

Windows 高对比度模式下渐变文字会怎样?

强制颜色模式下,浏览器会把 color 替换成系统文字色、去掉背景渐变;在 Chromium 中模拟 forced-colors: active 时,透明文字最终以系统文字色显示、仍然可见。但这依赖各浏览器对「透明文字 + 背景裁切」的强制逻辑,处理不完全一致;本条显式写了 @media (forced-colors: active):去掉背景、color: CanvasText、停止动画,结果不受浏览器差异影响。

常见搭配

同一页面里经常和「流动渐变文字」一起出现的模式,可以收藏后用「组合收藏为整页提示词」一起交给 AI。

所属设计风格

「流动渐变文字」是这些整体设计风格的常见组成部分,在设计风格词典里可以看到整页效果。

标签