中文
动廊把动效说清楚
Typography · CSS only

Text shimmer

文字渐变扫光

Sweep a band of light across text, continuously.

Also searched as: 一道光从文字上扫过, 标题文字的渐变高光流动, 文字闪光扫过, 让品牌词一直微微发光

AI Markdown (.md)
Placement
Hero heading
Mood
Refined, Technical
Trigger
一直循环
Site types
个人网站, 作品集, 工具站

How it works & accessibility

Clip a background three times wider than the text to the glyphs with background-clip: text and animate background-position from 90% to 0% so a bright band passes; both ends show only the base color so the loop is seamless, unsupported browsers get solid text, and reduced motion keeps it still.

Best for: Hero heading (一直循环).

Reduced motion: 不扫光,文字停在底色

Mobile & touch: 和桌面一样;手机上一直在扫比较费电,可以只在首屏用

Key parameters

ParameterKeyDefaultRangeNotes
扫一次多久duration2400ms——
光带的倾斜角度angle100°——

Ready-to-paste AI prompt

Add “Text shimmer” to the hero heading in my project: Clip a background three times wider than the text to the glyphs with background-clip: text and animate background-position from 90% to 0% so a bright band passes; both ends show only the base color so the loop is seamless, unsupported browsers get solid text, and reduced motion keeps it still.
Parameters: duration: 2400ms, angle: 100°.
Preserve existing content and layout. Respect prefers-reduced-motion by showing the final state. Content must remain visible if JavaScript fails or is disabled.
Reference: https://donglang.linter.top/effects/text-shimmer.md (canonical specification and reference code).

Dependency-free reference code

CSS
/* 文字渐变扫光(Text shimmer)· 只用 CSS,不需要脚本。参考 StyleKit 的 text-gradient-flow、Animation Handbook 的 text-gradient-animation 的做法(都是 MIT),
   自己实现,没有复制代码。用法:给要发光的文字加 class="tsh"。
   做法:文字用 background-clip: text 把背景画进字形里;背景是一张比文字宽 3 倍的渐变(亮带在图的 40%–60%),
   背景位置从 90% 挪到 0%:起点时窗口只看得到图右边的底色,终点时只看得到左边的底色,所以一圈的首尾都是纯底色、接得上,亮带从左往右扫过;
   repeat-x 保证窗口外也是底色。
   - 颜色:--tsh-base 是平时的字色(要和底色有足够的对比度),--tsh-light 是亮带的颜色;深色背景上把亮带换成浅色、底色换成中灰。
   - 一圈多久:--tsh-duration;亮带倾斜多少:--tsh-angle(90deg 是竖直的一条)。
   - 不支持 background-clip: text 的浏览器:就是 --tsh-base 颜色的纯色文字,照样看得见。
   - 开启"减少动态"时:不扫,文字停在底色。 */
/* 默认值写在 :where() 里(不占优先级):网站自己在 .tsh 上改的变量,不管写在这段代码前面还是后面,都用网站自己的 */
:where(.tsh) {
  --tsh-duration: 2400ms;
  --tsh-angle: 100deg;
  --tsh-base: #6b7280;
  --tsh-light: #ffffff;
}
.tsh {
  color: var(--tsh-base);
}
@supports (background-clip: text) or (-webkit-background-clip: text) {
  .tsh {
    background: linear-gradient(var(--tsh-angle), var(--tsh-base) 40%, var(--tsh-light) 50%, var(--tsh-base) 60%) 90% 0 / 300% 100% repeat-x;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    animation: tsh-sweep var(--tsh-duration) linear infinite;
  }
}
@keyframes tsh-sweep {
  from { background-position-x: 90%; }
  to { background-position-x: 0%; }
}
@media (prefers-reduced-motion: reduce) {
  .tsh { animation: none; background-position-x: 90%; }
}
HTML
<!-- 文字渐变扫光:给要发光的那个词加 class="tsh",不需要脚本。字色、亮带颜色、一圈多久用 CSS 变量改 -->
<h1>把动效<span class="tsh" style="--tsh-base: #1f2937; --tsh-light: #ffffff;">说清楚</span></h1>

More in Typography

Browse all 86 effects →

Shown once per release · Always available in changelog