Skip to content
Inspireca Design

Interactive Example · Hover states

Link underline that appears on hover and focus

A hover effect for navigation links that works just as well for keyboard users, and moves nothing else on the page.

Written by Inspireca Design (drafted with AI assistance)Updated Not yet reviewed by an editor

Try it

Use it with a mouse, by touch or with the keyboard. The controls below show its other states.

Preview controls

How it works

Hover effects are often the first animation added to a site and the first to cause trouble: they shift the layout, or they exist only for people with a mouse. This one avoids both.

What moves

The underline is a separate two-pixel strip under the text. It grows from the start of the word in 200 milliseconds, or fades in if you choose that style. Because the strip is scaled rather than given a width, the browser does not have to lay the page out again and neighbouring links stay still.

Hover is not a state you can rely on

Touch screens have no hover. Anything a person needs to know must be visible without it. Here the links are already recognisable as navigation by their position and weight; the underline only confirms which one you are on. Never hide information or controls behind hover alone.

When to use it

Navigation links and text buttons in headers and footers. Links inside a paragraph should be underlined all the time, because there the underline is how people find them.

Accessibility notes

  • Same effect on focus. The underline appears on :focus-visible as well as hover, and there is a separate focus ring, so keyboard users can always see where they are (WCAG 2.2, 2.4.7 Focus Visible).
  • Not colour alone. The change is a shape, not only a colour shift (1.4.1 Use of Color).
  • Target size: each link is at least 44 px tall even though the text is smaller.
  • Reduced motion: the underline appears at once instead of growing.

The code

This is the source of the preview above: React with Tailwind CSS classes (underline-reveal-link.tsx). Colour names such as bg-primary and the ex- animation classes come from this site’s own stylesheet; replace them with your own.

"use client";

import type { DemoProps } from "@/lib/examples/keys";

const LINKS = ["Pricing", "Changelog", "Documentation"];

/**
 * Navigation links whose underline appears on hover AND on keyboard focus. The underline is a
 * pseudo-element that is scaled or faded, so nothing around it moves.
 */
export default function UnderlineRevealLink({ values }: DemoProps) {
  const effect = values.style === "fade"
    ? "after:opacity-0 hover:after:opacity-100 focus-visible:after:opacity-100 after:transition-opacity"
    : "after:origin-left after:scale-x-0 hover:after:scale-x-100 focus-visible:after:scale-x-100 after:transition-transform";
  return (
    <nav aria-label="Example links">
      <ul className="flex flex-wrap justify-center gap-x-8 gap-y-3">
        {LINKS.map((label) => (
          <li key={label}>
            <a
              href="#"
              onClick={(e) => e.preventDefault()}
              className={`relative inline-flex min-h-11 items-center rounded-sm text-[17px] font-medium text-foreground outline-none focus-visible:ring-2 focus-visible:ring-foreground focus-visible:ring-offset-4 after:absolute after:inset-x-0 after:bottom-2 after:h-0.5 after:rounded-full after:bg-foreground after:duration-200 after:ease-out motion-reduce:after:transition-none ${effect}`}
            >
              {label}
            </a>
          </li>
        ))}
      </ul>
    </nav>
  );
}

See it in real apps

Still screenshots from the Inspireca Design library of the kinds of screen where this interaction is used. A screenshot cannot show the motion itself.

  • Interactive Examples

    Button press, loading and success feedback

    A button that dips when pressed, shows a spinner while it works and confirms when it is done, with words that carry the meaning at every step.

  • Interactive Examples

    Tabs with a sliding indicator

    A marker that slides to the selected tab shows where you came from and where you are, with full arrow-key support.

  • Interactive Examples

    Card that expands in place

    A summary card that opens to show its details without leaving the page, built on a real button and a height animation that needs no measuring.

  • Interactive Examples

    Dropdown menu with keyboard support

    A menu that opens from its button with a short fade and scale, and can be used completely from the keyboard.