Favorites

10 Different CSS Animated Links

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
CSS Animated Text Links

Links are one of the most important parts of any website, and a small animation when someone hovers over or focuses on a link can make an interface feel polished and responsive. In this post we'll build 10 different animated link effects with CSS, from subtle underlines to sliding backgrounds, each with a live demo you can try by hovering over it, or by pressing Tab to reach it with the keyboard.

Every effect in this post follows a few rules that keep links easy to use:

  • Hover and keyboard focus get the same effect. Each rule uses both :hover and :focus-visible, so keyboard users see the animation too.
  • Animations use transform, opacity or colour wherever possible. These are cheap for the browser to animate, so the effects stay smooth.
  • Text colours have strong contrast, so links are readable in every state, not just before or after the animation.
  • Movement switches off for people who prefer reduced motion (more on this near the end).

Tip: some of these effects remove the standard underline. That's fine for navigation menus and buttons, where it's obvious that something is a link. For links within paragraphs of text, keep an underline, as effects 3, 4 and 8 do, so people can find links without relying on colour alone.

1. Slide-in underline

.link-slide {
  position: relative;
  text-decoration: none;
}

.link-slide::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: 2px;
  background: currentColor;     /* same colour as the text */
  transform: scaleX(0);
  transform-origin: right;      /* shrink away to the right */
  transition: transform 0.3s ease;
}

.link-slide:hover::after,
.link-slide:focus-visible::after {
  transform: scaleX(1);
  transform-origin: left;       /* grow in from the left */
}

A line drawn with ::after grows in from the left on hover, then slides away to the right when the pointer leaves. The trick is switching transform-origin: on hover the line grows from the left edge, and afterwards it shrinks towards the right edge. Animating transform: scaleX() rather than width keeps the movement smooth, because the browser doesn't have to recalculate the layout on every frame.

2. Centre-out underline

.link-centre {
  position: relative;
  text-decoration: none;
}

.link-centre::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: 2px;
  background: currentColor;
  transform: scaleX(0);         /* transform-origin defaults to the centre */
  transition: transform 0.3s ease;
}

.link-centre:hover::after,
.link-centre:focus-visible::after {
  transform: scaleX(1);
}

The same idea, but because transform-origin is left at its default (the centre), the line grows outwards from the middle in both directions. It's a tidy effect for navigation menus.

3. Thickening underline

.link-thick {
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  transition: text-decoration-thickness 0.2s ease, text-underline-offset 0.2s ease;
}

.link-thick:hover,
.link-thick:focus-visible {
  text-decoration-thickness: 3px;
  text-underline-offset: 2px;
}
Results
Links inside paragraphs should keep an underline, like this thickening link, so readers can spot them without relying on colour.

This effect uses the real text underline, so it works perfectly for links within paragraphs. On hover, the line gets thicker and moves a little closer to the text. Because the underline is always visible, people can tell it's a link at a glance, even before hovering.

4. Colour fade

.link-fade {
  color: #1d4ed8;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.3s ease;
}

.link-fade:hover,
.link-fade:focus-visible {
  color: #be185d;
}

The simplest effect of all: the colour changes smoothly instead of instantly. Both colours have a contrast ratio of over 6:1 against white, so the text stays easy to read in either state.

5. Gradient text swipe

.link-gradient {
  text-decoration: none;
  background: linear-gradient(90deg, #1d4ed8, #7c3aed, #be185d, #1d4ed8) 0 0 / 300% 100%;
  -webkit-background-clip: text;   /* for older browsers */
  background-clip: text;           /* show the background only inside the text */
  color: transparent;              /* let the gradient show through */
  transition: background-position 0.6s ease;
}

.link-gradient:hover,
.link-gradient:focus-visible {
  background-position: 100% 0;
}

background-clip: text trims the background to the shape of the letters, and the transparent text colour lets the gradient show through. The gradient is three times wider than the link, so moving its position slides different colours across the text. Every colour in the gradient is dark enough to read on white.

6. Text glow

.link-glow {
  text-decoration: none;
  transition: text-shadow 0.3s ease;
}

.link-glow:hover,
.link-glow:focus-visible {
  text-shadow:
    0 0 10px rgb(37 99 235 / 0.55),
    0 0 2px rgb(37 99 235 / 0.4);
}

Two soft, unoffset shadows create a gentle glow around the letters. The original version of this post used a tiny 1px 1px 2px shadow that was barely visible; the glow is clearer while keeping the text sharp.

7. Background slide

.link-bgslide {
  position: relative;
  isolation: isolate;          /* keep the ::before layer inside the link */
  display: inline-block;
  overflow: hidden;
  padding: 10px 22px;
  border-radius: 8px;
  background: #1d4ed8;
  color: #ffffff;
  text-decoration: none;
}

.link-bgslide::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;                 /* behind the text */
  background: #be185d;
  transform: translateX(-101%);
  transition: transform 0.4s ease;
}

.link-bgslide:hover::before,
.link-bgslide:focus-visible::before {
  transform: translateX(0);
}

A second colour, waiting just out of view to the left, slides in behind the text. Two changes from the original make it more reliable: it moves with transform instead of animating left, and isolation: isolate keeps the z-index: -1 layer inside the link, so it can't slip behind the page background. The text stays white throughout, as it's readable on both colours. The original switched the text to black on red, which was hard to read.

8. Highlighter sweep

.link-highlight {
  color: #1f2937;
  text-decoration: underline;
  text-decoration-color: #d97706;
  text-underline-offset: 3px;
  background: linear-gradient(#fde68a, #fde68a) no-repeat 0 90% / 0% 45%;
  box-decoration-break: clone;   /* repeat the effect on each line if it wraps */
  transition: background-size 0.4s ease;
}

.link-highlight:hover,
.link-highlight:focus-visible {
  background-size: 100% 45%;
}
Results
A highlighter effect suits links within longer paragraphs of text, because it works even when a link wraps onto two lines.

A solid-colour "gradient" sits along the lower half of the text with a width of 0%. On hover it grows to 100%, like a highlighter pen being drawn across the words. Unlike effects built on pseudo-elements, it follows the text across line breaks, so it's ideal for links in paragraphs.

9. Circle reveal

.link-circle {
  position: relative;
  isolation: isolate;
  display: inline-block;
  overflow: hidden;             /* clip the circle to the link's box */
  padding: 10px 22px;
  border: 2px solid #1d4ed8;
  border-radius: 8px;
  color: #1d4ed8;
  text-decoration: none;
  transition: color 0.3s ease;
}

.link-circle::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: -1;
  width: 120%;
  aspect-ratio: 1;              /* a perfect circle */
  border-radius: 50%;
  background: #1d4ed8;
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.4s ease;
}

.link-circle:hover,
.link-circle:focus-visible {
  color: #ffffff;
}

.link-circle:hover::before,
.link-circle:focus-visible::before {
  transform: translate(-50%, -50%) scale(1);
}

A circle grows from the centre until it fills the button. In the original version, the circle was the same width and height as the link, so it was really an oval and never quite covered the corners. Making it a true circle with aspect-ratio: 1, slightly wider than the link, means it fills the whole shape.

10. Text roll

<a class="link-roll" href="/about/">
  <span data-text="About us">About us</span>
</a>
.link-roll {
  display: inline-block;
  overflow: hidden;           /* hide the copy until it rolls into view */
  vertical-align: bottom;
  text-decoration: none;
}

.link-roll span {
  position: relative;
  display: inline-block;
  transition: transform 0.3s ease;
}

.link-roll span::after {
  content: attr(data-text);         /* fallback for older browsers */
  content: attr(data-text) / "";    /* empty alt text: don't read it twice */
  position: absolute;
  top: 100%;                        /* sits just below the original text */
  left: 0;
  color: #be185d;
}

.link-roll:hover span,
.link-roll:focus-visible span {
  transform: translateY(-100%);
}

A copy of the text, made with ::after and attr(), waits just below the link, hidden by overflow: hidden. On hover, both roll upwards, so the original slides out and the coloured copy slides in. The empty alternative text (/ "") stops screen readers from announcing the link text twice.

What happened to the flips? The original version of this post included two 3D flip effects using rotateY() and rotateX(). They had several problems: perspective set on the link itself doesn't add depth to the link's own rotation, the text appeared mirrored halfway through, and as the link turned edge-on, the pointer could slip off it and cause flickering. The text roll gives a similar sense of movement without those issues. A constantly pulsing glow effect has also been dropped, as endless animation draws attention away from the rest of the page.

Respect reduced motion

Some people find movement on screen uncomfortable, and turn on a "reduce motion" setting on their device. You can detect it with the prefers-reduced-motion media query and make transitions instant:

@media (prefers-reduced-motion: reduce) {
  a,
  a::before,
  a::after,
  a * {
    transition-duration: 0.01ms;
  }
}

The hover styles still apply, so links still respond, but without the movement. The demos in this post use this technique.

Keep focus visible

A hover animation isn't a substitute for a focus indicator. Keyboard users need a clear outline to see where they are, so keep one, as the demos do:

a:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 4px;
}

Remember touch screens

Phones and tablets don't have a hover state, so these animations mostly won't be seen there. Make sure every link looks like a link before any animation happens, through its underline, colour, position or button styling, rather than relying on the hover effect to reveal it.

Use real links

The original demos used href="javascript:void(0)". Links should always point somewhere real. If something performs an action on the page instead of going to another page, it should be a <button>, not a link.

EffectBest for
Thickening underline, colour fade, highlighter sweepLinks within paragraphs of text
Slide-in and centre-out underlines, text rollNavigation menus and footers
Gradient text, text glowHeadings or a single standout link
Background slide, circle revealLinks styled as buttons, such as calls to action

Whichever you choose, use one or two effects consistently across your site rather than mixing many. Consistency helps people learn what's clickable.

For more underline ideas, see our post on CSS animated underline links.

Wrapping up

Small link animations can make a site feel crafted and responsive, and all ten effects here need only a few lines of CSS. Animate transform and colour for smooth results, apply effects on :focus-visible as well as :hover, keep underlines on links within text, and respect reduced-motion preferences, and your links will look good and work well for everyone.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee