CSSeasyCSS

Animated Underline on Hover

Create an animated underline effect for links and navigation items.

01

The problem

You want links to have an animated underline that slides in on hover.

02

The solution

CSS
/* Slide from left */
.underline-left {
  position: relative;
  text-decoration: none;
  color: inherit;
}

.underline-left::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, #3a7bff, #8b5cf6);
  transition: width 0.3s ease;
}

.underline-left:hover::after {
  width: 100%;
}

/* Slide from center */
.underline-center {
  position: relative;
  text-decoration: none;
}

.underline-center::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  width: 0;
  height: 2px;
  background: #3a7bff;
  transition: all 0.3s ease;
}

.underline-center:hover::after {
  left: 0;
  width: 100%;
}

/* Highlight effect */
.underline-highlight {
  background: linear-gradient(transparent 60%, rgba(58, 123, 255, 0.3) 60%);
  transition: background 0.3s ease;
}

.underline-highlight:hover {
  background: linear-gradient(transparent 60%, rgba(58, 123, 255, 0.6) 60%);
}

03

See it live

Isolated previewSandboxed
04

Put it to work

Example
<nav>
  <a href="#" class="underline-left">Home</a>
  <a href="#" class="underline-center">About</a>
  <a href="#" class="underline-highlight">Contact</a>
</nav>

Worth knowing

Remove default text-decoration for these effects. Great for navigation menus.