AI CSS Animations

Corner Border Link Hover

Two corner marks bracket the link at rest and stretch along the edges until they close into a full box on hover. Four gradient layers on the link itself, no extra elements.

Also known as: corners to box hover, border draw link, box outline link hover.

HTML

<a class="hfx-link-corner-border" href="#">View the archive</a>

CSS

.hfx-link-corner-border {
  --c: var(--hfx-color, #3b82f6);
  position: relative;
  display: inline-block;
  color: var(--c);
  font: 600 calc(var(--hfx-size, 16px) * 1.25)/1.3 system-ui, sans-serif;
  text-decoration: none;
  padding: 0.4em 0.75em;
  background:
    linear-gradient(var(--c) 0 0) 0 0 / 0.7em 0.1em,
    linear-gradient(var(--c) 0 0) 0 0 / 0.1em 0.7em,
    linear-gradient(var(--c) 0 0) 100% 100% / 0.7em 0.1em,
    linear-gradient(var(--c) 0 0) 100% 100% / 0.1em 0.7em;
  background-repeat: no-repeat;
  transition: background-size 0.4s cubic-bezier(0.65, 0, 0.35, 1);}
.hfx-link-corner-border:is(:hover, :focus-visible) {
  background-size: 100% 0.1em, 0.1em 100%, 100% 0.1em, 0.1em 100%;
}

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

Underline Grow Link
Underline from Center Link
Highlighter Link
Slide Up Text Link