Skip to content
IndexRequest a UIAboutContact

Animated Underline Link

Text links whose underline slides in from one side and out the other on hover.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Create a list of three text links (Library, Request a UI, About), 18px medium weight, spaced 28px apart. Draw the underline with a background-image linear-gradient (currentColor) sized 0% 1.5px at position right bottom, no-repeat. On hover and :focus-visible set the background-size to 100% 1.5px and the position to left bottom, transitioning background-size over 320ms cubic-bezier(.2,.7,.2,1); because the position switches at the start of hover and the start of leave, the line enters from the left and exits to the right. While pressed increase the line height to 3px. Do not change layout. Under @media (hover:none) show a static 1px underline. Under prefers-reduced-motion remove transitions. Keep a 2px outline on focus-visible in addition to the line. Links prevent navigation in the demo.

About this pattern

Definition

Links with an underline drawn by a background gradient. On hover the line enters from the left; when the pointer leaves it exits to the right, giving a feeling of the pointer sweeping across.

Purpose & UX principles

  • A refined hover cue that does not shift layout.
  • The underline also appears on keyboard focus, so focus is as visible as hover.
  • Links keep a resting colour contrast of at least 4.5:1; the animation is an enhancement, not the only affordance.

Interaction states

  • Rest (no line or thin line on touch), hover and focus (full line), pressed (line thickens), visited.

Motion specification

  • Enter and exit: 320ms cubic-bezier(.2,.7,.2,1), animating background-size and background-position.
  • Reduced motion: the line appears and disappears instantly.

Responsive behaviour

  • Works with any font size since the line is positioned in em.
  • On touch there is no hover, so links keep a static thin underline.

Code

HTML
<nav class="lk" aria-label="Demo links"><a href="#">Library</a><a href="#">Request a UI</a><a href="#">About</a></nav>

Related patterns

Top Navigation

↗
Top NavigationNavigation

Tab Navigation

↗
Tab NavigationNavigation

Ripple Effect

↗
Ripple EffectButtons & Actions