All effectsPlay & loop

Border Beam

边框流光

A short streak of light travels around the outline of a card or button.

Play the light around the edge

Where to use it

Draw attention to a featured card, active panel, or occasional call to action. Use one moving highlight in a group so the light marks a clear priority and the neighboring options stay easy to compare.

Practical example

A service-plan comparison highlights its team plan with a short beam that circles the card while visitors review the choices. The prices and the selected-plan indicator sit on a steady surface inside the border.

Also called

  • Traveling Border Light

AI prompt

Add a Border Beam to [target card]. Send a short gradient beam around the actual outline at a steady pace and keep it clipped to the border and existing radius. Keep the contents readable and pointer events available. Provide a pause control for looping motion and use a static accent with reduced motion.

Example code

Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.

View HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Border Beam</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    @property --beam-angle { syntax: '<angle>'; inherits: false; initial-value: 22deg; }
    .beam-card {
      position: relative;
      display: grid;
      place-items: center;
      gap: 7px;
      width: min(100%, 206px);
      min-height: 98px;
      padding: 13px;
      border: 1px solid #51466e;
      border-radius: 17px;
      background: #28223e;
      color: #e9e0fb;
      font-size: 13px;
      font-weight: 650;
    }
    .beam-edge {
      position: absolute;
      inset: -1px;
      padding: 2px;
      border-radius: inherit;
      background: conic-gradient(from var(--beam-angle, 22deg), transparent 0deg 290deg, #a779ff 312deg, #ebdcff 346deg, transparent 358deg);
      mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
      mask-composite: exclude;
      pointer-events: none;
      animation: travel-beam 3.6s linear infinite;
    }
    .beam-mark { display: grid; place-items: center; color: #c6adff; font-size: 25px; line-height: 1; }
    @keyframes travel-beam { to { --beam-angle: 382deg; } }

    .loop-example {
      display: grid;
      gap: 12px;
      justify-items: center;
      width: min(100%, 290px);
    }
    .loop-example [data-motion] { animation-play-state: paused; }
    .loop-example[data-playing] [data-motion] { animation-play-state: running; }
    @media (prefers-reduced-motion: reduce) {
      .loop-example [data-motion] { animation: none; }
      .loop-example [data-loop-toggle] { display: none; }
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="loop-example">
      <div class="beam-card">
        <span class="beam-edge" aria-hidden="true" data-motion></span>
        <span class="beam-mark" aria-hidden="true">✧</span>
        <span>Featured plan</span>
      </div>
      <button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">Play demo</button>
    </div>
  </main>
  <script>
    const example = document.querySelector('.loop-example');
    const toggle = example.querySelector('[data-loop-toggle]');

    toggle.addEventListener('click', () => {
      const playing = example.toggleAttribute('data-playing');
      toggle.textContent = playing ? "Pause demo" : "Play demo";
    });
  </script>
</body>
</html>

Original example by UI Skills

Further examples