YL

TEXT EFFECT

环形旋转文字Spinning Text

文字沿圆周排列,跟随页面滚动整体旋转(按时间自转时需配暂停按钮),中间留空放图标或简短标签。Magic UI 的 spinning-text 就是它。

中英对照

中文
环形旋转文字
英文
Spinning Text
别名
Circular Text、Rotating Badge、Orbit Text
一句话
文字沿圆周排列,跟随页面滚动整体旋转(按时间自转时需配暂停按钮),中间留空放图标或简短标签。Magic UI 的 spinning-text 就是它。

效果预览

SPINNING TEXT · 环形旋转文字 · SPINNING TEXT · 环形旋转文字 ·
✦

适合用在哪

认证徽章、限量标签、「滚动我」提示、页脚角落的品牌印记。

不适合:承载重要信息的文案(价格、截止日期、活动规则):一直在转的小字几乎不可能被完整读完;页面上已经有其他持续运动的元素(跑马灯、背景视频)时也不要再加,同屏多处运动会让注意力无处安放。

和相近模式的区别

路径文字Text Path

路径文字是静态的弧线排版,读起来像一个弯曲的标题,适合印章和 Logo 周围的品牌名;环形旋转文字把文案绕满一整圈并持续旋转,中间留空放图标,作用是一个吸引注意的徽章或「向下滚动」提示,文字本身不指望被完整读完,所以可访问名称要另外写清。

容易踩的坑

  • 文案长度不足以绕满一圈,首尾之间留出一段难看的空白缺口。
  • 9.5px 中性灰小字持续旋转,几乎无法被完整读出。
  • 旋转的 SVG 文字对读屏无意义:给外层链接写 aria-label,或给 <svg> 加 role="img" 和 aria-label;普通 div 上的 aria-label 不可靠。

设计提示词 · Prompt

环形旋转文字(Spinning Text):用 SVG 画一个半径 46px 的圆路径(d="M59,59 m-46,0 a46,46 0 1,1 92,0 a46,46 0 1,1 -92,0"),<textPath> 里放重复两遍的文案(保证绕满一圈,词间用「 · 」分隔)。整个 <svg> 跟随页面滚动旋转 360deg(animation-timeline: scroll(root block),用 @supports 门控,不支持时保持静止);如需按时间线性 12s 自转,必须提供可见的暂停按钮,悬停与聚焦时也暂停(WCAG 2.2.2)。旋转的 <svg> 加 aria-hidden,名称写在外层链接的 aria-label 上,并以可见文案开头(没有链接时给 <svg> 加 role="img" 和 aria-label)。中心用绝对定位放一个 36×36px 的渐变圆,内嵌图标或短字母。文字 fill 用中性灰、字号 9.5px、字距 0.08em。
Spinning Text: use SVG to draw a circular path with radius 46px (d="M59,59 m-46,0 a46,46 0 1,1 92,0 a46,46 0 1,1 -92,0"), and put the copy repeated twice inside <textPath> (to ensure it wraps a full circle, separated by " · "). The whole <svg> rotates 360deg with page scroll (animation-timeline: scroll(root block), gated by @supports and static where unsupported); if it must spin on its own linearly over 12s, provide a visible pause button and also pause on hover and focus (WCAG 2.2.2). Mark the rotating <svg> aria-hidden and put the name, starting with the visible copy, in the outer link's aria-label (without a link, give the <svg> role="img" and an aria-label). In the center, absolutely position a 36×36px gradient circle containing an icon or short letters. Text fill is neutral gray, font size 9.5px, letter-spacing 0.08em.

可复制 CSS

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

/* <a class="spin" href="#next" aria-label="Scroll down,跳到下一节">
     <svg viewBox="0 0 118 118" aria-hidden="true">
       <defs><path id="spin-ring" d="M59,59 m-46,0 a46,46 0 1,1 92,0 a46,46 0 1,1 -92,0"/></defs>
       <text><textPath href="#spin-ring">SCROLL DOWN · KEEP SCROLLING · SCROLL DOWN · </textPath></text>
     </svg>
     <span class="spin__core" aria-hidden="true">✦</span>
   </a>
   默认跟随页面滚动旋转;要按时间自转,加 .spin--auto,并配可见的暂停按钮切换 .is-paused */
.spin {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  color: #4b5563;
  text-decoration: none;
}
.spin > svg { width: 100%; height: 100%; overflow: visible; }
.spin path { fill: none; }
.spin text {
  fill: currentColor;
  font: 600 9.5px/1 system-ui, sans-serif;
  letter-spacing: .08em;
}
.spin__core {
  position: absolute;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4f46e5, #c026d3);
  color: #fff;
}
.spin:focus-visible { outline: 2px solid #6366f1; outline-offset: 4px; }
/* 用户不滚动就不转,不属于自动播放 */
@supports (animation-timeline: scroll()) {
  .spin > svg {
    animation: spin-turn linear both;
    animation-timeline: scroll(root block);
  }
}
.spin--auto > svg { animation: spin-turn 12s linear infinite; }
.spin--auto:hover > svg,
.spin--auto:focus-within > svg,
.spin--auto.is-paused > svg { animation-play-state: paused; }
@keyframes spin-turn {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .spin > svg,
  .spin--auto > svg { animation: none; }
}
@media (forced-colors: active) {
  .spin text { fill: CanvasText; }
}

演示 HTML 结构

<div class="s d-center">
  <div class="tx-spin">
    <svg viewBox="0 0 118 118">
      <defs><path id="uiTxS" d="M59,59 m-46,0 a46,46 0 1,1 92,0 a46,46 0 1,1 -92,0" fill="none"/></defs>
      <text><textPath href="#uiTxS">SPINNING TEXT · 环形旋转文字 · SPINNING TEXT · 环形旋转文字 · </textPath></text>
    </svg>
    <div class="tx-spin__c">✦</div>
  </div>
</div>

无障碍与性能

无障碍

  • 旋转的 SVG 加 aria-hidden="true",名称写在外层链接的 aria-label 上:名称要以可见文案开头,再写清链接做什么,如「Scroll down,跳到下一节」,语音控制用户说出看到的文字才能点中它(SC 2.5.3 标签包含在名称中);可见文案为了绕满一圈有重复,名称里不必重复。中心图标同样 aria-hidden。
  • SC 2.2.2:按时间无限自转属于自动开始、持续超过 5 秒的移动内容,徽章再小也没有例外。本条默认改为跟随滚动旋转,不支持滚动驱动动画时保持静止;.spin--auto 自转版必须配一个可见的暂停按钮,悬停和聚焦时也会暂停。
  • prefers-reduced-motion: reduce 时两种旋转都停掉;强制颜色模式下把文字 fill 显式设为 CanvasText,SVG 的 fill 不一定会被浏览器强制替换。

性能

  • 旋转的是整个 <svg> 元素的 transform,可以交给合成线程,不会每帧重绘文字。
  • 滚动驱动版不需要任何 JS,也不需要监听 scroll。

常见问题

环形旋转文字的英文是什么?

环形旋转文字的英文是 Spinning Text。常见英文别名还包括 Circular Text、Rotating Badge、Orbit Text。

Spinning Text 的中文是什么?

Spinning Text 的中文是「环形旋转文字」。文字沿圆周排列,跟随页面滚动整体旋转(按时间自转时需配暂停按钮),中间留空放图标或简短标签。Magic UI 的 spinning-text 就是它。

旋转徽章一直转,算不算违反 WCAG?

按 SC 2.2.2,自动开始、持续超过 5 秒、和其他内容同屏的移动内容,必须提供暂停、停止或隐藏的方式,按时间无限自转的徽章需要处理。三种做法:改成跟随滚动旋转(本条默认,用户不滚就不动,不属于自动播放);只在悬停时旋转;或者保留自转,同时提供可见的暂停按钮。prefers-reduced-motion 只是额外的系统级开关,不能代替暂停按钮。

怎么让文字刚好绕满一圈?

圆的周长是 2π × 半径,本条半径 46,周长约 289(viewBox 单位)。先用 text.getComputedTextLength() 量出文字长度,再微调 letter-spacing 或文案,让它接近 289:本条示例在 9.5px、0.08em 字距下约 288,换成「HANDMADE · SINCE 2016 · 」重复两遍则约 296,超出的部分会被裁掉;结果和字体有关,换字体要重新量。也可以在 <textPath> 上写 textLength="289" 和 lengthAdjust="spacing" 让浏览器自动调整字距,但各浏览器对这个属性的渲染不如手动调整稳定,上线前要逐个检查。

旋转中心为什么是歪的?

旋转整个 <svg> 元素时,transform-origin 默认是它自身盒子的中心,不会歪。歪的情况通常是旋转了 SVG 内部的 <g> 或 <text>:SVG 内部元素的 transform-origin 默认是 0 0,参照框是整个 viewBox(transform-box: view-box),元素会绕着左上角公转。给内部元素加 transform-box: fill-box 和 transform-origin: center,或者直接旋转外层 <svg>。

常见搭配

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

标签