AI CSS Animations

Flash Update Border

A balance card whose border flashes bright and decays each time the number ticks over, the way trading and finance dashboards flag a live update. One keyframe snaps the flash on and eases it out.

Also known as: flash border, flash border animation css, highlight on update css, value changed flash.

Total balance $12,480.20$12,806.45 +2.6% today

HTML

<div class="bdr-flash-update-border">
  <span class="bdr-flash-update-border-label">Total balance</span>
  <span class="bdr-flash-update-border-value"><span>$12,480.20</span><span>$12,806.45</span></span>
  <span class="bdr-flash-update-border-delta">+2.6% today</span>
</div>

CSS

.bdr-flash-update-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;
  box-sizing: border-box;
  place-items: initial;
  align-content: center;
  gap: 0.3em;
  padding: 0 1.4em;
  background: color-mix(in srgb, var(--c) 5%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 20%, transparent);
}
.bdr-flash-update-border::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: color-mix(in srgb, var(--c) 10%, transparent);
  box-shadow:
    inset 0 0 0 0.12em color-mix(in srgb, var(--c) 70%, #fff),
    0 0 0 0.12em color-mix(in srgb, var(--c) 30%, transparent),
    0 0 1.6em color-mix(in srgb, var(--c) 45%, transparent);
  opacity: 0;
  pointer-events: none;
  animation: bdr-flash-update-border-flash 3s infinite;
}
.bdr-flash-update-border-label {
  font-size: 0.72em;
  font-weight: 500;
  opacity: 0.6;
}
.bdr-flash-update-border-value {
  display: grid;
  overflow: hidden;
  font-size: 1.6em;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.bdr-flash-update-border-value span {
  grid-area: 1 / 1;
  animation: bdr-flash-update-border-tick 6s cubic-bezier(0.2, 0.8, 0.2, 1) infinite;
}
.bdr-flash-update-border-value span + span { animation-delay: -3s; }
.bdr-flash-update-border-delta {
  justify-self: start;
  padding: 0.2em 0.5em;
  border-radius: 1em;
  background: color-mix(in srgb, var(--c) 14%, transparent);
  color: var(--c);
  font-size: 0.7em;
}
@keyframes bdr-flash-update-border-flash {
  0%   { opacity: 0; animation-timing-function: cubic-bezier(0.2, 0, 0.4, 1); }
  3%   { opacity: 1; animation-timing-function: cubic-bezier(0.1, 0.6, 0.3, 1); }
  45%, 100% { opacity: 0; }
}
@keyframes bdr-flash-update-border-tick {
  0%        { opacity: 0; transform: translateY(0.5em); }
  5%, 50%   { opacity: 1; transform: none; }
  54%, 100% { opacity: 0; transform: translateY(-0.5em); }
}
@media (prefers-reduced-motion: reduce) {
  .bdr-flash-update-border::after { animation: none; }
  .bdr-flash-update-border-value span { animation: none; }
  .bdr-flash-update-border-value span + span { opacity: 0; }
}

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