Modern CSS Link Hover Effects: Animated Underlines, Strikethroughs & Magnetic Micro-Interactions

The Quick Answer

To create the popular left-to-right animated underline in modern CSS, set background: linear-gradient(currentColor, currentColor) no-repeat 0 100% / 0% 2px on the anchor tag and transition background-size 0.3s cubic-bezier(0.16, 1, 0.3, 1) to 100% 2px on :hover and :focus-visible. This outperforms older border-bottom hacks by preserving sub-pixel anti-aliasing and allowing precise vertical gap control with text-underline-offset.

Interactive Demo Live Preview
1. Left-to-Right Animated Underline → 2. Wavy SVG Contour Offset 3. Magnetic Pill Highlight

Step 1: The Left-to-Right Expanding Underline via CSS Backgrounds

Traditional CSS underlines defined via text-decoration: underline cannot be animated smoothly in older browsers. The modern front-end standard uses a CSS linear gradient as the background image, positioned at the bottom left of the anchor tag with a width of 0%. On hover or keyboard focus, the background width scales to 100%, creating a smooth horizontal wipe effect without layout recalculations.

link-ltr-underline.css
.nav-link {
  color: var(--text-primary);
  text-decoration: none;
  background-image: linear-gradient(currentColor, currentColor);
  background-position: 0% 100%;
  background-repeat: no-repeat;
  background-size: 0% 2px;
  transition: background-size 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  padding-bottom: 2px;
}

.nav-link:hover,
.nav-link:focus-visible {
  background-size: 100% 2px;
}

Step 2: Modern Native Properties: text-decoration-thickness and text-underline-offset

Modern CSS now provides first-class properties for native text decoration. Rather than hacking borders or pseudo-elements, you can use text-underline-offset to pull the line away from descending characters like 'g', 'y', and 'p', and text-decoration-thickness to set fractional sub-pixel widths.

native-underline.css
.article-link {
  color: #38bdf8;
  text-decoration: underline;
  text-decoration-color: rgba(56, 189, 248, 0.4);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 4px;
  transition: text-decoration-color 0.2s ease, text-underline-offset 0.2s ease;
}

.article-link:hover {
  text-decoration-color: #38bdf8;
  text-underline-offset: 7px;
}

Step 3: Interactive Pill Expansion & Ghost Highlights

For navigation links and sidebar menus, a full background fill creates a punchy, tactile interface. By combining a subtle translucent background with an offset box-shadow or pill border, the link signals clickable depth instantaneously.

pill-hover.css
.tab-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 9999px;
  color: var(--text-secondary);
  text-decoration: none;
  background: transparent;
  transition: background 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              color 0.25s ease,
              transform 0.25s ease;
}

.tab-link:hover {
  color: #fff;
  background: rgba(108, 99, 255, 0.15);
  transform: translateY(-1px);
}

Step 4: External Link Indicators & Keyboard Accessibility

Good UX demands that external links warn users that they will navigate away from the current domain. Using an inline SVG mask or CSS pseudo-element with :not([href^='#']) automatically appends an external arrow icon that animates upward and to the right on hover, while :focus-visible guarantees keyboard users never lose their place.

external-link.css
.external-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
}

.external-link::after {
  content: "↗";
  display: inline-block;
  font-size: 0.9em;
  transition: transform 0.2s ease;
}

.external-link:hover::after,
.external-link:focus-visible::after {
  transform: translate(2px, -2px);
}

Next-Level Addons: Elevating Your Implementation

Take this technique further by combining it with complementary design token studios and animation tools:

1. Link Micro-Button Hybrid with Spring Physics

Explore in Button Animations Studio →

Elevate high-value conversion links into hybrid text buttons that spring upward on hover while smoothly expanding their baseline highlight.

2. Holographic Iridescent Text Shimmer on Link Hover

Explore in Text Effects Studio →

Combine animated text gradient masks with link underline sweeps to give editorial links a luminous, magazine-style color shift.

Fluid Ease-Out Glide

3. Cubic-Bezier Glide Underline Animation

Explore in Animation Studio →

Replace linear timing with high-velocity ease-out curves so the link underline snaps into position with authentic physical weight.

Chaam
Chaam's Pro Tip

A trick I use in almost every project: don't fight specificity battles with !important. Leverage modern CSS cascade layers (@layer) and CSS variables as design tokens—it makes dark/light theme switching and responsive tuning effortless.

Why I Built the Link Effects Studio

I got tired of guessing values and testing browser quirks in DevTools, so I built this tool to tweak and preview values in real time with 1-click code export.

Open in Link Effects Studio ↗

Frequently Asked Questions

Practical answers to common implementation questions, browser quirks, and performance tips.

How do you animate an underline from left to right in CSS?

Set 'background-image: linear-gradient(currentColor, currentColor)' with 'background-position: 0 100%', 'background-repeat: no-repeat', and 'background-size: 0% 2px'. On :hover or :focus-visible, transition 'background-size' to '100% 2px' using a cubic-bezier timing function.

Can you animate text-decoration directly in CSS?

Modern browsers support transitions on 'text-underline-offset' and 'text-decoration-color'. However, smooth continuous scaling of underline width from 0% to 100% still requires using the CSS background-size trick or pseudo-elements.

How do you prevent link underlines from crossing descender characters (p, y, g)?

Declare 'text-decoration-skip-ink: auto;' on the anchor tag. This is enabled by default in modern browsers and automatically leaves clean optical gaps around letter tails.

What is the difference between text-underline-offset and border-bottom for links?

'text-underline-offset' is rendered natively by the text layout engine, naturally respecting multi-line text wraps and font descenders. 'border-bottom' treats the link as an inline box, which can collide with line-height and trigger unintended baseline shifts.

How do you ensure custom link hover effects are accessible to keyboard users?

Always pair every ':hover' pseudo-class selector with ':focus-visible' (e.g. '.link:hover, .link:focus-visible'). Never set 'outline: none' without providing an equivalent high-contrast visual focus indicator.

← Back to all blog guides Launch Generator Studio →