Underline Tabs

Tabs with a sliding underline that glides under the active tab.

Analytics content goes here.
Tailwind CSS
<div class="w-full max-w-md">
  <div class="relative grid grid-cols-3 border-b border-slate-200" role="tablist" aria-label="Content sections">
    <button type="button" role="tab" aria-selected="false" class="px-4 py-2.5 text-sm font-medium text-slate-500 dark:text-slate-400 transition-colors hover:text-slate-800 dark:hover:text-slate-200">Overview</button>
    <button type="button" role="tab" aria-selected="true" class="px-4 py-2.5 text-sm font-medium text-slate-900 dark:text-white">Analytics</button>
    <button type="button" role="tab" aria-selected="false" class="px-4 py-2.5 text-sm font-medium text-slate-500 dark:text-slate-400 transition-colors hover:text-slate-800 dark:hover:text-slate-200">Reports</button>
    <span class="absolute -bottom-px left-0 h-0.5 w-1/3 translate-x-full rounded-full bg-indigo-600 transition-transform duration-200"></span>
  </div>
  <div class="py-4 text-sm text-slate-600 dark:text-slate-300" role="tabpanel">Analytics content goes here.</div>
</div>

Free to use in personal and commercial projects. No attribution required.

Variants

Same component, different looks. Preview each one live and copy the code you like.

Dark

The dark tabs fit dashboards and settings pages with a dark theme.

Analytics content goes here.
Tailwind CSS

With counts

Count badges tell users how many items sit behind each tab before they click.

Analytics content goes here.
Tailwind CSS

Four tabs

The four-tab layout with the active state on the first tab suits settings pages with more sections.

Overview content goes here.
Tailwind CSS

About this underline tabs

Underline tabs are the quieter sibling of pill tabs: no background fills, just a short colored line that slides under whichever tab is active. This pattern dominates settings pages and profile sections where the design should stay light.

Equal grid columns make the math trivial. The underline is one third of the track width, absolutely positioned at the bottom border, and translate-x-full slides it exactly one column over for the second tab. The -bottom-px offset sits it directly on the border line, and the transition makes it glide when the active tab changes. This preview shows the second tab active.

Use it for profile pages, settings sections, and dashboard sub-navigation. In your app, move the translate class and the active text styles with your tab state, and keep aria-selected in sync for assistive technology.

Settings pages and profile sections need tab switching without the visual weight of pill tabs or boxed tabs. A short colored line gliding under the active tab says you are here while leaving the design light and typographic. It is the quietest tab pattern that still feels designed, which is why it dominates admin interfaces.

Equal grid columns make the math trivial. The underline is one third of the track width, absolutely positioned at the bottom border, and translate-x-full slides it exactly one column over per tab. The -bottom-px offset seats it directly on the border line, and the transition makes it glide instead of jump when the selection changes.

Slide the underline between tabs with a transform transition instead of re-rendering it per tab; the traveling line is what makes the control feel alive. Size the line to the label width, not the tab width, so short labels like FAQ don't get a long meaningless bar. When a tab is loading its panel, pulse the underline gently to show progress without blocking clicks. For icon-only tabs, center a short 24px line under the icon; a full-width line under a lone icon looks like a mistake.

Underline tabs are too subtle for primary navigation. Their whole virtue is quietness, which becomes a vice when the tabs are the main wayfinding of the page and users cannot tell where they are. Reserve this pattern for secondary, in-page switching. When the tabs ARE the navigation, use a bolder treatment with a filled background or stronger weight.

Where to use it

  • ✓ Profile page sections
  • ✓ Settings sub-navigation
  • ✓ Dashboard content tabs
  • ✓ Product detail tabs

Customization tips

Use grid-cols-4 with w-1/4 and translate-x steps for four tabs. Thicken the underline to h-1 for more presence. Swap indigo-600 for your brand color, or use a gradient via bg-gradient-to-r.

Design notes

When to use

Underline tabs suit content sections where the tab row should feel light, like Analytics, Reports, and Settings under a page header. The sliding underline gives the active tab a clear marker without the visual weight of filled pills. They work well when the tabs share one panel below them and switching never triggers a page load.

What to avoid

Do not mix underline tabs with pill tabs on the same page, two tab styles signal two different behaviors that do not exist. Avoid underline tabs for more than five options, the row overflows on mobile and the sliding indicator loses its elegance. And do not let the tab content jump in height wildly between tabs, the page bounce is jarring.

Accessibility

The tablist role with aria-selected on each tab is the right structure, keep it. Support arrow key navigation between tabs and make sure the sliding indicator is decorative, not the only sign of which tab is active.

Frequently asked questions

How do I animate an underline under the active tab?

Make each tab an equal grid column, then position an absolute underline at one column width and translate it by 100 percent per tab index. The transition-transform class animates the glide.

Why does the underline sit exactly on the border?

-bottom-px pulls it down one pixel so it overlaps the border-b line instead of floating above it. Without the offset there is a visible gap.

Are these tabs accessible?

Add role="tablist", role="tab", and aria-selected on each tab, with role="tabpanel" on the content. For full keyboard support, arrow keys should move between tabs per the WAI-ARIA tabs pattern.

How do I make the underline follow the hovered tab as well?

Listen for mouseenter on each tab, read its offsetLeft and offsetWidth, and move the indicator there with the same transition used for the active state. On mouseleave, snap it back to the active tab. This preview-on-hover pattern is common on marketing navs and makes the control feel alive.

Should I use underline tabs or pill tabs?

Use underline tabs for page-level navigation and content sections where the tabs sit against a background, they feel lighter and scan faster. Use pill tabs when the control floats over busy content or needs a stronger selected state, like filters on a card. Do not mix both styles in the same interface.

How do I keep the underline aligned when labels change size?

Recompute the indicator position on window resize and whenever the active tab changes, including after font loads which can shift text width. Store the measurement in a function you call from a resize observer, not just on click. If labels come from translations, measure after the text renders.