AI CSS Animations

Top Highlight Border

A bright gradient line glides back and forth along the top edge of a dark card and casts a soft light below it, the detail on many developer sites. Both layers move with transform only.

Also known as: gradient top border css, card top border light, top edge glow card css.

Changelog Builds are twice as fast.

HTML

<div class="bdr-top-highlight-border">
  <strong class="bdr-top-highlight-border-title">Changelog</strong>
  <span class="bdr-top-highlight-border-text">Builds are twice as fast.</span>
</div>

CSS

.bdr-top-highlight-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;
  align-content: center;
  gap: 0.3em;
  overflow: hidden;
  background: color-mix(in srgb, var(--c) 10%, #0b0f19);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #fff 10%, transparent);
  color: #f1f5f9;
}
.bdr-top-highlight-border::before,
.bdr-top-highlight-border::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 6em;
  pointer-events: none;
  animation: bdr-top-highlight-border-glide 4s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate;
}
.bdr-top-highlight-border::before {
  z-index: 1;
  height: 0.12em;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--c) 30%, #fff) 50%, transparent);
}
.bdr-top-highlight-border::after {
  height: 3.5em;
  background: radial-gradient(50% 100% at 50% 0, color-mix(in srgb, var(--c) 40%, transparent), transparent);
}
.bdr-top-highlight-border-title { font-size: 1.05em; }
.bdr-top-highlight-border-text {
  color: color-mix(in srgb, #fff 60%, transparent);
  font-size: 0.8em;
  font-weight: 400;
}
@keyframes bdr-top-highlight-border-glide {
  from { transform: translateX(0.5em); }
  to   { transform: translateX(8.5em); }
}

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