AI CSS Animations

External Link Arrow Hover

The north-east arrow beside an outbound link shoots out of its badge while a fresh copy slides in from the opposite corner, and the badge fills in. Two SVG arrows in a clipped circle.

Also known as: external link icon animation, diagonal arrow hover, arrow up right link.

HTML

<a class="hfx-link-external-arrow" href="#">Open the demo<span class="hfx-link-external-arrow-badge" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M7 17 17 7M8 7h9v9"/></svg><svg viewBox="0 0 24 24"><path d="M7 17 17 7M8 7h9v9"/></svg></span></a>

CSS

.hfx-link-external-arrow {
  --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;
  display: inline-flex;
  align-items: center;
  gap: 0.4em;}
.hfx-link-external-arrow-badge {
  position: relative;
  width: 1.2em;
  height: 1.2em;
  border-radius: 50%;
  overflow: hidden;
  background: color-mix(in srgb, var(--c) 14%, transparent);
  transition: background-color 0.3s ease, color 0.3s ease;
}
.hfx-link-external-arrow-badge svg {
  position: absolute;
  inset: 0.25em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.4s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-link-external-arrow-badge svg + svg { transform: translate(-1.2em, 1.2em); }
.hfx-link-external-arrow:is(:hover, :focus-visible) .hfx-link-external-arrow-badge {
  background: var(--c);
  color: #fff;
}
.hfx-link-external-arrow:is(:hover, :focus-visible) .hfx-link-external-arrow-badge svg { transform: translate(1.2em, -1.2em); }
.hfx-link-external-arrow:is(:hover, :focus-visible) .hfx-link-external-arrow-badge svg + svg { transform: translate(0, 0); }

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