CSS Gradient Underline Link

A link with a thin gradient underline that grows into a full highlight on hover, even across lines.

  • link
  • hover
  • background-size
  • fill
  • multi-line
HTML
<p class="link-grad-text">Read our <a class="link-grad" href="#">guide to accessible color</a> before you ship.</p>
CSS
.link-grad-text {
  max-width: 15em;
  margin: 0;
  color: #334155;
  font: 500 20px/1.6 system-ui, sans-serif;
}

.link-grad {
  padding: 0 0.1em;
  color: #312e81;
  font-weight: 700;
  text-decoration: none;
  background: linear-gradient(90deg, #4f46e5, #db2777) no-repeat left bottom / 100% 3px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background-size 0.3s ease, color 0.3s ease;
}

.link-grad:hover,
.link-grad:focus-visible {
  background-size: 100% 100%;
  color: #ffffff;
}

.link-grad:focus-visible {
  outline: 2px solid #312e81;
  outline-offset: 2px;
}

About this CSS Gradient Underline Link

This CSS Gradient Underline Link is 28 lines of pure CSS (0.6 KB) with no JavaScript and no dependencies. It uses transitions, linear gradients and keyboard focus styles. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

The colors in this snippet. Search and replace them to match your brand:

  • #334155
  • #312e81
  • #4f46e5
  • #db2777
  • #ffffff

How to use this gradient underline link

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .link-grad-text class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback