中文
Click & feedback · CSS only

Pulse ring

脉冲光环

Send rings pulsing outward from a button, continuously.

Also searched as: 按钮外面一圈一圈扩散的光环, 提醒这里可以点的脉冲圈, 小红点一圈圈往外扩散, 呼吸一样往外扩的光圈

AI Markdown (.md)
Placement
Button
Mood
Playful, Crisp
Trigger
一直循环
Site types
个人网站, 工具站

How it works & accessibility

Two outline rings that inherit the button's radius scale up and fade out on a CSS loop, offset by half a cycle; they ignore pointer events and are aria-hidden, and with reduced motion one static ring (4px outside the button, 0.6 opacity) stays and the second ring is hidden.

Best for: Button (一直循环).

Reduced motion: 不扩散,留一个静止的光环(第一个圈停在按钮外面 4px、透明度 0.6,第二个圈不显示),按钮本身不受影响

Mobile & touch: 和桌面一样;手机上一直在动比较费电,点过就把光环去掉

Key parameters

ParameterKeyDefaultRangeNotes
一圈多久duration1600ms——
扩到多大spread1.8倍——

Ready-to-paste AI prompt

Add “Pulse ring” to the button in my project: Two outline rings that inherit the button's radius scale up and fade out on a CSS loop, offset by half a cycle; they ignore pointer events and are aria-hidden, and with reduced motion one static ring (4px outside the button, 0.6 opacity) stays and the second ring is hidden.
Parameters: duration: 1600ms, spread: 1.8×.
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/pulse-ring.md (canonical specification and reference code).

Dependency-free reference code

CSS
/* 脉冲光环(Pulse ring)· 只用 CSS,不需要脚本。参考 StyleKit 的 pulse-ring、Animation Handbook 的 badge-pulse 的做法(都是 MIT),自己实现,没有复制代码。
   用法:<span class="pr" style="border-radius: 999px"><button …>…</button><i class="pr-ring" aria-hidden="true"></i><i class="pr-ring" aria-hidden="true"></i></span>
   - .pr 是外框:和按钮一样大,border-radius 写在它上面(圈的圆角从它继承,和按钮一样);
   - 两个圈 .pr-ring 盖在按钮外面,从原大小放大到 --pr-spread 倍;透明度先在前 15% 亮到 0.6、再淡到 0(首尾都看不见,一圈接得上),一直循环;
     第 2 个圈晚半圈,看起来一圈接一圈;
   - 圈的颜色是 --pr-color(默认跟着文字颜色);一圈多久是 --pr-duration;圈不挡点击(pointer-events: none)、读屏读不到(aria-hidden);
   - 开启"减少动态"时:不扩散,留一个静止的光环(第一个圈停在按钮外面 4px、半透明),照样提示"这里有新东西";第二个圈不显示,按钮本身不受影响。
   - 外框的 display: inline-grid 不在 :where() 里(它是叠层的做法):网站自己在 .pr 上改 display 会让圈叠不到按钮上,改之前想一想。 */
/* 默认值和定位写在 :where() 里(不占优先级):网站自己在 .pr 上改的变量、外框自己写的定位(absolute 这些),
   不管写在这段代码前面还是后面,都用网站自己的 */
:where(.pr) {
  --pr-duration: 1600ms;
  --pr-spread: 1.8;
  position: relative;
}
.pr {
  display: inline-grid;
}
.pr-ring {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid var(--pr-color, currentColor);
  opacity: 0;
  pointer-events: none;
  animation: pr-pulse var(--pr-duration) ease-out infinite;
}
.pr-ring + .pr-ring {
  animation-delay: calc(var(--pr-duration) / 2);
}
/* 圈在一圈的开头是透明的、很快(前 15%)亮到 0.6,再一边放大一边淡到 0:一圈的首尾都看不见,接得上,不会"啪"地冒出来 */
@keyframes pr-pulse {
  0% { scale: 1; opacity: 0; }
  15% { opacity: 0.6; }
  100% { scale: var(--pr-spread); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .pr-ring { animation: none; inset: -4px; opacity: 0.6; }
  .pr-ring + .pr-ring { opacity: 0; }
}
HTML
<!-- 脉冲光环:按钮外面套一层 .pr,后面放两个圈;圈的圆角跟着 .pr 的 border-radius。点过以后把两个圈去掉(这里只是摆出来) -->
<span class="pr" style="border-radius: 999px; --pr-color: #e5484d;">
  <button type="button" aria-label="通知(有 3 条新消息)">🔔</button>
  <i class="pr-ring" aria-hidden="true"></i>
  <i class="pr-ring" aria-hidden="true"></i>
</span>

More in Click & feedback

Browse all 86 effects →

Shown once per release · Always available in changelog