Pill Tabs

Segmented pill tabs with active state.

Tailwind CSS
<div class="inline-flex rounded-2xl bg-slate-100 p-1.5 gap-1">
  <button class="px-5 py-2 rounded-xl text-sm font-bold bg-white shadow text-slate-900">Overview</button>
  <button class="px-5 py-2 rounded-xl text-sm font-bold text-slate-500 hover:text-slate-700 transition-colors">Features</button>
  <button class="px-5 py-2 rounded-xl text-sm font-bold text-slate-500 hover:text-slate-700 transition-colors">Pricing</button>
  <button class="px-5 py-2 rounded-xl text-sm font-bold text-slate-500 hover:text-slate-700 transition-colors">Reviews</button>
</div>

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

About this pill tabs

Tabs organize related content into switchable panels without page loads. The pill variant, with its rounded container and sliding active background, is the modern standard you see in dashboards, settings pages, and product pages. A tailwind tabs component like this one is pure markup: buttons in a flex container, with the active one getting a white background and shadow.

There are two main tab styles. Pill tabs (this one) suit contained panels like settings. Underline tabs suit page-level navigation like GitHub's repo tabs. Pick pill tabs when the tab bar sits inside a card or panel.

For a functional tab switcher, add JavaScript that toggles the active classes and shows the matching panel. Keep tab labels to one or two words. If you have more than five tabs, consider a dropdown or scrollable tab bar instead.

Related content split across pages forces reloads; crammed onto one page it forces scrolling. Tabs solve it with instant switching between views of the same content: Overview, Features, Pricing, no navigation cost. The pill variant signals that these options belong together through its shared track, and the active pill's shadow makes the current selection obvious at a glance.

The container is inline-flex rounded-2xl bg-slate-100 p-1.5 gap-1. The active button gets bg-white shadow text-slate-900, which reads as a physical pill sitting in the gray track; inactive buttons are text-slate-500 with a hover darkening. That white-on-gray contrast is the entire visual system. A few lines of JavaScript swap the active classes and show the matching panel.

For a sliding indicator, render one pill element behind the buttons and glide it to the active tab with translate-x, measuring each button's offsetLeft and offsetWidth for exact placement. Add small count badges inside tabs for quantified views like Reviews (128). On mobile, let the bar scroll horizontally with overflow-x-auto rather than shrinking labels into illegibility.

The keyboard mistake is switching panels on click without moving focus or supporting arrow keys, so keyboard users tab through content they cannot see. Follow the ARIA tab pattern: arrow keys move between tabs, and selection moves focus into the panel. Tabs that only work with a mouse are broken for a meaningful share of users.

Design notes

When to use

Pill tabs work best when you have two to four views of the same content that users switch between often, like Overview, Features, and Pricing on a product page. The filled track behind the options tells users these choices belong together and only one can be active. Because the active pill carries a shadow and the inactive ones sit flat, the current selection reads instantly without any label needed.

What to avoid

Do not use pill tabs for navigation that takes users to different pages, that job belongs to real links or a nav bar. Tabs that trigger a full page load will feel broken because users expect tab switches to be instant. Also avoid squeezing in more than five options, the pills get cramped and the row starts to wrap on mobile.

Accessibility

Give each tab button aria-selected and wrap the set in a container with role tablist so screen readers announce the active tab. Make sure arrow keys can move between tabs, not just the Tab key, since that matches how native tab controls behave.

Variants

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

Indigo active

Use a colored active tab when the tab bar is the main navigation on the page.

Tailwind CSS

With counts

Add count badges when tabs filter lists, like inbox categories.

Tailwind CSS

Vertical

Stack tabs vertically for settings sidebars and narrow panels.

Tailwind CSS

Where to use it

  • ✓ Settings panels
  • ✓ Product page sections
  • ✓ Dashboard views
  • ✓ Profile pages

Frequently asked questions

Pill tabs vs underline tabs, which should I use?

Pill tabs suit contained panels like settings cards. Underline tabs suit page-level navigation. Pill tabs feel more modern; underline tabs are more traditional.

How do I make tabs functional?

Add click handlers that swap the active button styles and toggle hidden on the corresponding content panels. Use aria-selected and role=tablist for accessibility.

How many tabs is too many?

Five is the practical max for visible tabs. Beyond that, use a scrollable tab bar or a dropdown selector.

How do I add a sliding pill indicator to tabs?

Render an absolutely positioned pill behind the tab labels, then measure the active tab's offsetLeft and offsetWidth in JavaScript and set the pill's transform and width to match. Transition both properties for the slide. Recalculate on resize so the indicator stays aligned.

How do I make pill tabs with no JavaScript?

Use hidden radio inputs with labels styled as pills. The :checked state of each radio styles its label as active via the adjacent sibling selector, and shows the matching panel with a general sibling selector. All radios share one name so only one tab is active at a time.

How do I make pill tabs scrollable on mobile?

Wrap the tab row in a container with overflow-x auto and flex nowrap, and give each tab flex-shrink 0 so labels never wrap. Hide the scrollbar with scrollbar-width none and the webkit pseudo-element for a clean look. Add scroll-padding so the active tab never hides under an edge fade.

Customization tips

For an animated sliding indicator, use a single absolutely-positioned pill that translates to the active tab. Add counts with small badges inside tabs. On mobile, allow horizontal scroll with overflow-x-auto.

Related elements

1
2
3

Checkout Stepper

Multi-step progress indicator for checkout flows.

Breadcrumbs

SEO-friendly breadcrumb navigation with schema.

Pagination

Clean pagination with prev/next and page numbers.