Chapter 6: Tabs

How to create tabs (also called tabbed interfaces, tab navigation, tab panels, etc.) from the very beginning.

What are Tabs?

Tabs are a very common UI pattern that lets users switch between different sections of content without leaving the page.

You see them everywhere:

  • Product pages (Description / Reviews / Specifications)
  • Settings pages
  • Dashboard analytics
  • FAQ pages
  • Code editors (multiple files open)
  • Browser dev tools

Goals of good tabs (keep this in mind)

  • Clear which tab is active
  • Easy to click / tap (especially on mobile)
  • Content changes instantly or with smooth transition
  • Accessible with keyboard (Tab key + Enter/Space)
  • Works well on small screens
  • Only loads/shows relevant content

We will build four progressively better versions:

  1. Pure CSS tabs (no JavaScript) – very simple
  2. Classic JavaScript tabs (most common style)
  3. Modern accessible tabs with <tablist>, <tab>, <tabpanel> roles
  4. Bonus: Tabs with fade / slide animation

Let’s go slowly.

Version 1 – Pure CSS Tabs (no JavaScript)

This uses radio buttons + labels (very clever trick).

HTML

CSS

Pros

  • No JavaScript
  • Very fast
  • Works with JS disabled

Cons

  • Only one tab active at a time (by design)
  • Harder to add dynamic content later
  • Accessibility is okay but not great

Version 2 – JavaScript Tabs (most common real-world approach)

HTML

CSS

JavaScript

Very important: data-tab attribute links button to panel id.


Version 3 – Accessible Tabs (ARIA + best practices 2025–2026)

HTML

JavaScript (with ARIA updates)

JavaScript

Quick comparison – which method to choose?

Goal Best choice Needs JS? Accessibility Animation possible? Mobile friendly
Super simple, no JS Pure CSS (radio) No Medium Limited Good
Classic & flexible JS + data attributes Yes Good Yes Very good
Professional / production ARIA roles + keyboard support Yes Excellent Yes Excellent
Very modern look Tailwind / Headless UI / Radix UI Yes Excellent Yes Perfect

Bonus: Adding a nice fade transition

Add this CSS:

CSS

Now panels fade in/out smoothly.

Would you like to go deeper into any of these topics?

Examples:

  • How to make vertical tabs (left sidebar style)
  • How to make tabs scroll horizontally on mobile
  • How to lazy-load tab content (only load when opened)
  • How to make tabs with icons
  • How to do tabs in React / Vue / Tailwind
  • Common accessibility mistakes
  • How to animate with slide instead of fade
  • How to make tabs look like browser tabs

Just tell me which part you want explained slowly with full examples — I’m here for you. 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *