AI CSS Animations

Blinking Border

A warning border that flashes twice, holds, and repeats, so the box grabs attention without moving. The flash is a hard step on the border layer's opacity, not a fade, like an alarm light.

Also known as: css border blink animation, css border flash animation, flashing border css.

Unsaved changes

HTML

<div class="bdr-blinking-border">
  <svg class="bdr-blinking-border-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3 2 20h20L12 3Z"/><path d="M12 10v4m0 3v.01"/></svg>
  Unsaved changes
</div>

CSS

.bdr-blinking-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;
  grid-auto-flow: column;
  gap: 0.5em;
  justify-content: center;
  background: color-mix(in srgb, var(--c) 7%, transparent);
}
.bdr-blinking-border::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 0.14em solid var(--c);
  border-radius: inherit;
  box-shadow: 0 0 0.7em color-mix(in srgb, var(--c) 55%, transparent), inset 0 0 0.5em color-mix(in srgb, var(--c) 30%, transparent);
  pointer-events: none;
  animation: bdr-blinking-border-flash 2.2s step-end infinite;
}
.bdr-blinking-border-icon {
  width: 1.3em;
  height: 1.3em;
  fill: none;
  stroke: var(--c);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
@keyframes bdr-blinking-border-flash {
  0%, 20%, 100% { opacity: 1; }
  10%, 30%      { opacity: 0.12; }
  40%           { opacity: 1; }
}

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