AI CSS Animations

Corner Border Card Hover

Four accent corner brackets stretch along the edges until they meet and close the frame. It is eight background layers on one pseudo-element, and background-size is the only thing that moves.

Also known as: corner border hover effect, corner brackets css, border grows from corners.

03

Brand identity

Logo, type and color for a small coffee roaster.

HTML

<article class="hfx-card-corner-brackets">
  <span class="hfx-card-corner-brackets-num">03</span>
  <h3>Brand identity</h3>
  <p>Logo, type and color for a small coffee roaster.</p>
</article>

CSS

.hfx-card-corner-brackets {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  position: relative;
  box-sizing: border-box;
  width: 14em;
  padding: 1.2em 1.3em 1.3em;
  background: color-mix(in srgb, var(--c) 0%, transparent);
  font-family: system-ui, sans-serif;
  transition: background-color 0.4s ease;
}
.hfx-card-corner-brackets:hover { background: color-mix(in srgb, var(--c) 7%, transparent); }
.hfx-card-corner-brackets::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(var(--c) 0 0) 0 0 / 1.2em 2px no-repeat,
    linear-gradient(var(--c) 0 0) 0 0 / 2px 1.2em no-repeat,
    linear-gradient(var(--c) 0 0) 100% 0 / 1.2em 2px no-repeat,
    linear-gradient(var(--c) 0 0) 100% 0 / 2px 1.2em no-repeat,
    linear-gradient(var(--c) 0 0) 0 100% / 1.2em 2px no-repeat,
    linear-gradient(var(--c) 0 0) 0 100% / 2px 1.2em no-repeat,
    linear-gradient(var(--c) 0 0) 100% 100% / 1.2em 2px no-repeat,
    linear-gradient(var(--c) 0 0) 100% 100% / 2px 1.2em no-repeat;
  transition: background-size 0.5s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-card-corner-brackets:hover::before {
  background-size: 50.5% 2px, 2px 50.5%, 50.5% 2px, 2px 50.5%, 50.5% 2px, 2px 50.5%, 50.5% 2px, 2px 50.5%;
}
.hfx-card-corner-brackets-num {
  display: inline-block;
  font: 700 0.75em ui-monospace, monospace;
  color: var(--c);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.hfx-card-corner-brackets:hover .hfx-card-corner-brackets-num { transform: translateX(0.4em); }
.hfx-card-corner-brackets h3 {
  margin: 0.4em 0 0.3em;
  font-size: 1.05em;
  font-weight: 600;
}
.hfx-card-corner-brackets p {
  margin: 0;
  font-size: 0.8em;
  line-height: 1.45;
  opacity: 0.7;
}

@media (prefers-reduced-motion: reduce) {
  .hfx-card-corner-brackets, .hfx-card-corner-brackets *, .hfx-card-corner-brackets::before, .hfx-card-corner-brackets::after, .hfx-card-corner-brackets *::before, .hfx-card-corner-brackets *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --hfx-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --hfx-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 hover effects