AI CSS Animations

Shine Border

A bright glint sweeps across a gradient border every few seconds, with a faint sheen crossing the box behind it. The glint is a second background layer whose position animates, masked to the edge.

Also known as: shiny border css, border shimmer animation, light sweep border css.

Shine border

HTML

<div class="bdr-shine-border">Shine border</div>

CSS

.bdr-shine-border {
  --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) 10%, #0b0f19);
  color: #f1f5f9;
}
.bdr-shine-border::before,
.bdr-shine-border::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  animation: bdr-shine-border-sweep 3.5s cubic-bezier(0.45, 0, 0.2, 1) infinite;
}
.bdr-shine-border::before {
  padding: 0.16em;
  background:
    linear-gradient(110deg, transparent 44%, #fff 50%, transparent 56%) 100% 0 / 250% 100% no-repeat,
    linear-gradient(135deg, color-mix(in srgb, var(--c) 40%, transparent), var(--c) 35% 65%, color-mix(in srgb, var(--c) 40%, transparent));
  -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);
}
.bdr-shine-border::after {
  background: linear-gradient(110deg, transparent 44%, color-mix(in srgb, #fff 8%, transparent) 50%, transparent 56%) 100% 0 / 250% 100% no-repeat;
}
@keyframes bdr-shine-border-sweep {
  0%        { background-position: 100% 0, 0 0; }
  60%, 100% { background-position: 0% 0, 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  .bdr-shine-border, .bdr-shine-border *, .bdr-shine-border::before, .bdr-shine-border::after, .bdr-shine-border *::before, .bdr-shine-border *::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