Navigation✨ Premium

Underline Slide

Pure CSS animated underline: transform: scaleX() + dual transform-origin — the bar slides in from the left on hover and exits to the right on mouse-out. Zero JS.

CSSSlide

You'll get access to the interactive demo with a free account.

This effect is part of Effect.Labs — 811 vanilla effects, some free, some premium. Navigation has 36 effects, including 4 free. Explore the category →

3 usage examples

Main navigation — Dark site header — Underline Slide example 1

① Main navigation — Dark site header

WhenHorizontal navigation bar at the top of a site (SaaS, portfolio, agency) with 3 to 6 primary links.
WhyThe underline slide provides precise, directional hover feedback without overloading a minimal nav — text color and bar change in sync, reinforcing readability of the active state.
Settingsheight: 2px, background: #6366f1 (indigo brand), transition: transform .3s, text #a1a1aa#fff.
Component tabs — Settings panel — Underline Slide example 2

② Component tabs — Settings panel

WhenHorizontal tabs inside a dashboard or account page (Profile, Security, Billing, Notifications) where the animation should indicate navigation direction.
WhyThe directional bar slide (left → right on enter) creates a spatial cue when the user scans tabs from left to right.
Settingsheight: 3px, brand-aligned color, transition: transform .2s for responsiveness. Combined with an .active class that forces scaleX(1) on the current tab.
Editorial mega-menu — Premium press & e-commerce header — Underline Slide example 3

③ Editorial mega-menu — Premium press & e-commerce header

WhenMain navigation of a press site or high-end e-commerce store: five horizontal categories in 17 px on a dark background, links well-spaced at the top of the page.
WhyLarger, well-spaced links on a dark background fully expose the bar's directional slide — the left-entry becomes immediately readable and signals the site's premium finish.
Settingsfont-size: 17px on items, height: 2px, background: #6366f1, transition: transform .3s, text #a1a1aa#fff.

How it works

The effect is 100% CSS, no JavaScript. The .link-underline-slide::after pseudo-element creates a 2 px bar (background: #6366f1, indigo) spanning the full link width (width: 100%), anchored at the bottom with position: absolute; bottom: 0. By default, transform: scaleX(0) hides it; only the transform property is transitioned (transition: transform .3s). At the same time, .nav-link-demo transitions its color from #a1a1aa (zinc-400) to #ffffff over the same 0.3 s.

The core mechanism is a dual transform-origin switch. At rest: transform-origin: right center — the scaling pivot is anchored to the right. On :hover: transform-origin: left center — the pivot instantly flips to the left (the property is not transitioned). Only scaleX is interpolated.

The double anchor creates an asymmetric animation. On hover-in: pivot at left, scaleX goes 0→1 — the bar grows from the left edge toward the right. On hover-out: pivot flips back to right, scaleX goes 1→0 — the left edge retreats toward the right anchor while the right edge stays fixed. The underline enters from the left and exits to the right without ever retracing the same path, giving the impression of a directional slide.

Accessibility

  • prefers-reduced-motion not present in the code. CSS transitions run even when the user has requested reduced motion. Add manually: @media (prefers-reduced-motion: reduce) { .link-underline-slide::after { transition: none; } }.
  • Text contrast meets WCAG AA in both states: #a1a1aa on #0a0a0f (≈ 5.8:1 at rest) and #ffffff on #0a0a0f (21:1 on hover).
  • The effect relies solely on :hover — no tabindex or :focus-visible in the base code. For <span> elements, add tabindex="0" and .link-underline-slide:focus-visible::after { transform: scaleX(1); transform-origin: left center; } for keyboard users.
  • The hover signal combines two independent visual cues (text color + underline) — meets WCAG 1.4.1 without relying on color alone.
  • No aria-* attributes in the base code. If elements remain <span>, add role="link"; if they are <a> tags, a valid href is sufficient for accessibility.

Browser compatibility

Uses transform, transform-origin, and ::after — supported in all modern browsers since IE 9. Zero external dependencies.

Chrome 49+✓ Full
Firefox 16+✓ Full
Safari 9+✓ Full
Edge 14+✓ Full
Mobile iOS✓ Full
Android Chrome✓ Full

Without CSS transition support (very old browsers), the underline appears and disappears instantly — no JS errors, navigation remains fully functional.

The code

HTML structure to paste into your page (CSS + JS available with a premium account):

index.html — structure
<div class="nav-demo">
  <span class="nav-link-demo link-underline-slide">Home</span>
  <span class="nav-link-demo link-underline-slide">Services</span>
  <span class="nav-link-demo link-underline-slide">Contact</span>
</div>
🔒 Unlock the full code — from €2.99 the first month

Full HTML + CSS + JS, copy-paste ready — with hundreds of premium effects.

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
--text-secondary #a1a1aa Text color at rest (root CSS variable). Adjust to your navigation gray.
--text-primary #ffffff Text color on hover. Replace with your primary color if the background isn't black.
background in ::after #6366f1 Underline bar color. Replace with your brand color or use currentColor to inherit from the text.
height in ::after 2px Bar thickness. 1 px = subtle (footer), 3–4 px = prominent (active tabs).
transition: transform .3s in ::after 0.3s Underline animation duration. 0.2 s = snappy and responsive, 0.4 s = softer.
transition: color .3s in .nav-link-demo 0.3s Text color transition duration. Sync with the underline duration for a unified feel.
transform-origin (default state and :hover) right / left Swapping the two values (left center by default, right center on hover) reverses the animation direction: enters from the right, exits to the left.

FAQ

On any inline element (<a>, <span>, <li>, <button>) — just apply the class link-underline-slide and make sure the element has position: relative. On an <a>, add text-decoration: none to remove the browser's native underline before your animated bar takes over.
Yes. Simply swap the two transform-origin values in the CSS: set left center in the default state and right center in the :hover::after block. The underline will then enter from the right and exit to the left.
Not by default — the code uses only :hover. For keyboard-navigable links, add .link-underline-slide:focus-visible::after { transform: scaleX(1); transform-origin: left center; }. This shows the full underline on focus and meets WCAG 2.4.7 (visible focus).