AI CSS Animations

Dual Border Beam

Two beams leave the top in opposite directions, cross at the bottom and meet again at the top. Two conic arcs read one @property angle, the second one mirrored, so they always meet in the middle.

Also known as: two beams border animation, opposite direction border animation, crossing border light.

Dual beam

HTML

<div class="bdr-dual-border-beam">Dual beam</div>

CSS

@property --bdr-dual-border-beam-a {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
.bdr-dual-border-beam {
  --c: var(--bdr-color, #3b82f6);
  font-size: var(--bdr-size, 16px);
  position: relative;
  display: grid;
  place-items: center;
  width: 15em;
  height: 8.5em;
  border-radius: 1em;
  font-family: system-ui, sans-serif;
  font-weight: 600;
  background: color-mix(in srgb, var(--c) 7%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 22%, transparent);
}
.bdr-dual-border-beam::before {
  content: "";
  position: absolute;
  inset: 0;
  padding: 0.15em;
  border-radius: inherit;
  background:
    conic-gradient(from var(--bdr-dual-border-beam-a), transparent 0 78%, var(--c) 99.5%, transparent 0),
    conic-gradient(from calc(var(--bdr-dual-border-beam-a) * -1), transparent 0 0.5%, color-mix(in oklch, var(--c), #ec4899 85%) 0, transparent 21.5%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  pointer-events: none;
  animation: bdr-dual-border-beam-cross 4s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
@keyframes bdr-dual-border-beam-cross {
  0%   { --bdr-dual-border-beam-a: 0deg; }
  50%  { --bdr-dual-border-beam-a: 180deg; }
  100% { --bdr-dual-border-beam-a: 360deg; }
}

@media (prefers-reduced-motion: reduce) {
  .bdr-dual-border-beam, .bdr-dual-border-beam *, .bdr-dual-border-beam::before, .bdr-dual-border-beam::after, .bdr-dual-border-beam *::before, .bdr-dual-border-beam *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --bdr-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --bdr-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar border animations