AI CSS Animations

Corner Brackets Border

Four corner brackets stretch along the edges until they close into a full frame, hold, then pull back into corners. Eight gradient strips on one pseudo-element, sized by a single keyframe.

Also known as: css animated corners, corner border animation, corners to full border.

In focus

HTML

<div class="bdr-corner-brackets-border">In focus</div>

CSS

.bdr-corner-brackets-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;
  border-radius: 0.2em;
  background: color-mix(in srgb, var(--c) 6%, transparent);
}
.bdr-corner-brackets-border::before {
  content: "";
  position: absolute;
  inset: 0;
  --h: linear-gradient(var(--c) 0 0) no-repeat;
  background:
    var(--h) 0 0, var(--h) 0 0,
    var(--h) 100% 0, var(--h) 100% 0,
    var(--h) 0 100%, var(--h) 0 100%,
    var(--h) 100% 100%, var(--h) 100% 100%;
  pointer-events: none;
  animation: bdr-corner-brackets-border-close 4s cubic-bezier(0.7, 0, 0.3, 1) infinite;
}
@keyframes bdr-corner-brackets-border-close {
  0%, 12%, 100% { background-size: 1.4em 0.16em, 0.16em 1.4em; }
  44%, 68%      { background-size: 51% 0.16em, 0.16em 51%; }
}

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