Skip to content

渐变文字

渐变文字的CSS动画效果,纯CSS实现,无需JavaScript。

实时预览

Flowing Colors

代码

css
.gradient-text {
  font-size: 42px;
  font-weight: 900;
  background: linear-gradient(
    90deg,
    #ff0080,
    #ff8c00,
    #40e0d0,
    #7c3aed,
    #ff0080
  );
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: gradient-flow 3s linear infinite;
}

@keyframes gradient-flow {
  to { background-position: 200% center; }
}
html
<span class="gradient-text">Flowing Colors</span>

纯 CSS 实现的渐变文字文字动画效果——通过渐变、阴影、滤镜和变换等 CSS 属性让文字产生视觉动效。所有文字内容保持可选中、可复制、对搜索引擎完全可见。

快速使用

  1. 复制 CSS 代码到你的样式文件中
  2. 在 HTML 中放入对应的文字结构(注意逐字效果需要每个字符包裹 <span>
  3. 根据你的文字内容调整 animation-delay 和文字数量
  4. 修改颜色和字号以匹配你的品牌风格

使用场景

  • 页面主标题:用渐变文字、霓虹发光或逐字弹跳效果吸引用户注意力
  • 品牌名称/Logo:3D 文字或故障效果传递技术与设计感
  • 营销活动页:彩虹文字、闪烁效果营造促销紧迫感
  • 技术博客/文档:打字机效果展示代码片段或技术标语

常见问题

Q: 文字动画在哪些浏览器下兼容? A: 大部分效果所有现代浏览器都支持。需注意:background-clip: text-webkit- 前缀;@property 仅 Chrome/Edge 支持。渐变文字和霓虹发光效果建议加降级方案。

Q: 动画文字会影响 SEO 吗? A: 不会。文字内容仍然在 HTML 中正常渲染,搜索引擎能完整抓取。CSS 动画只影响视觉呈现,不改变 DOM 结构和文本可访问性。

Q: 如何让逐字动画适配任意长度的文字? A: 用 JavaScript 动态给每个字符包裹 <span> 并设置 animation-delay: calc(var(--i) * 0.05s),或使用 CSS animation-delay 配合 nth-child 错位。

浏览器兼容性

浏览器兼容性
Chrome / Edge✅ 完全支持(含 @property
Firefox✅ 基本支持(不含 @property
Safari✅ 基本支持(需 -webkit-background-clip
移动端浏览器✅ 完全支持
IE 11❌ 渐变文字等高级效果不支持

使用说明

属性说明
background-clip: textClips the gradient to the text shape
-webkit-text-fill-color: transparentMakes the text fill transparent so the gradient shows through
background-size: 200% autoDoubles the gradient width for smooth looping
background-position animationShifts the gradient from 0% to 200% for seamless flow
Gradient stopsFirst and last color should match for smooth looping

Tip: Change the linear-gradient angle to 45deg for diagonal flow, or use radial-gradient for a pulsing center effect.