React Tab Components: 5 Accessible Tab Styles

Updated 2026-10-28. 5 tabs.

Tabs switch between panels of related content in the same spot. An accessible React tab component uses role tablist, tab and tabpanel, lets arrow keys move between tabs, Home and End jump to the ends, and gives only the selected tab a tabindex of zero. All five versions here follow that pattern.

The underline style is the default for page sections and settings screens: quiet, familiar and good with many tabs. Pills or a segmented control suit two to four short options that feel like a view switch, such as Monthly and Yearly or Map and List. Vertical tabs are for longer labels and settings pages where the left column doubles as navigation.

Add count badges when each tab is a filtered list and the numbers help people decide where to look, like an inbox or an issue tracker. Card tabs, with a raised selected tab joined to its panel, read well in product pages and pricing details where each panel is a block of real content rather than a list.

Compare them

VariantBuilt withSize (gzipped)Running costBrowser support
Underline Tabs With Sliding IndicatorCSS and a small script1.6 KBOne measurement per change and a transform transition; a resize observer keeps it aligned.All current browsers
Card Tabs With Content PanelsCSS only1.7 KBPlain colours and one small transform offset on the unchosen tabs; no transitions.All current browsers
Segmented Pill Tabs for Switching ViewsCSS only1.8 KBA single pill moves with translateX by whole segment widths; no measuring is needed.All current browsers
Tabs With Count BadgesCSS only1.5 KBStatic styles only; the counts come from the list lengths, so there is nothing to keep in sync.All current browsers
Vertical Tabs With Settings PanelsCSS only1.6 KBNo transitions; switching shows one small definition list and hides the others.All current browsers

Underline Tabs With Sliding Indicator

Four tabs for a coworking space listing: Overview, Amenities, Pricing and Location. A thin blue line under the labels slides and stretches to fit whichever tab is chosen, and each panel holds a heading and a short paragraph. On a narrow phone the row scrolls sideways and the chosen tab is scrolled into view.

<div class="ust">
  <div class="ust-scroll">
    <div class="ust-list" role="tablist" aria-label="Harbour Loft workspace">
      <button type="button" role="tab" id="ust-t1" aria-controls="ust-p1" aria-selected="true" tabindex="0">Overview</button>
      <button type="button" role="tab" id="ust-t2" aria-controls="ust-p2" aria-selected="false" tabindex="-1">Amenities</button>
      <button type="button" role="tab" id="ust-t3" aria-controls="ust-p3" aria-selected="false" tabindex="-1">Pricing</button>
      <button type="button" role="tab" id="ust-t4" aria-controls="ust-p4" aria-selected="false" tabindex="-1">Location</button>
      <span class="ust-bar" aria-hidden="true"></span>
    </div>
  </div>
  <div class="ust-panel" role="tabpanel" id="ust-p1" aria-labelledby="ust-t1" tabindex="0"><h3>A quiet room above the harbour</h3><p>Twelve desks, two phone booths and a meeting room for six, a short walk from the ferry terminal. Open from 7am to 9pm on weekdays.</p></div>
  <div class="ust-panel" role="tabpanel" id="ust-p2" aria-labelledby="ust-t2" tabindex="0" hidden><h3>What is included</h3><p>Fibre broadband, a kitchen with proper coffee, lockers, printing, showers and secure bike storage in the courtyard.</p></div>
  <div class="ust-panel" role="tabpanel" id="ust-p3" aria-labelledby="ust-t3" tabindex="0" hidden><h3>From $240 a month</h3><p>Flexible desks are $240, a fixed desk is $360 and a day pass is $28. No setup fee and one month's notice.</p></div>
  <div class="ust-panel" role="tabpanel" id="ust-p4" aria-labelledby="ust-t4" tabindex="0" hidden><h3>4 Wharf Lane, upstairs</h3><p>Two minutes from the ferry, five from the main bus stops. Street parking after 6pm and a loading bay for deliveries.</p></div>
</div>
<style>
  .ust { --ust-accent: #2563eb; max-width: 42rem; margin: 0 auto; padding: 48px 16px; font-family: ui-sans-serif, system-ui, sans-serif; color: #0f172a; }
  .ust :focus-visible { outline: 2px solid var(--ust-accent); outline-offset: 2px; }
  .ust-scroll { overflow-x: auto; }
  .ust-list { position: relative; display: flex; gap: 24px; border-bottom: 1px solid #e2e8f0; }
  .ust-list button { height: 48px; padding: 0 4px; border: 0; background: none; color: #475569; font: 500 14px ui-sans-serif, system-ui, sans-serif; white-space: nowrap; cursor: pointer; }
  .ust-list button:hover, .ust-list button[aria-selected="true"] { color: #0f172a; }
  .ust-bar { position: absolute; left: 0; bottom: -1px; width: 100px; height: 2px; border-radius: 2px; background: var(--ust-accent); transform-origin: left; transition: transform .3s ease-out; }
  .ust-panel { padding-top: 32px; border-radius: 8px; }
  .ust-panel h3 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
  .ust-panel p { margin: 12px 0 0; color: #475569; line-height: 1.75; }
  @media (prefers-reduced-motion: reduce) { .ust-bar { transition: none; } }
</style>
<script>
  (function () {
    document.querySelectorAll(".ust").forEach(function (root) {
      var list = root.querySelector(".ust-list"), bar = root.querySelector(".ust-bar");
      var tabs = Array.prototype.slice.call(root.querySelectorAll('[role="tab"]'));
      function place() {
        var t = list.querySelector('[aria-selected="true"]');
        bar.style.transform = "translateX(" + t.offsetLeft + "px) scaleX(" + t.offsetWidth / 100 + ")";
      }
      function select(i) {
        tabs.forEach(function (t, j) {
          t.setAttribute("aria-selected", i === j);
          t.tabIndex = i === j ? 0 : -1;
          root.querySelector("#" + t.getAttribute("aria-controls")).hidden = i !== j;
        });
        tabs[i].focus();
        place();
      }
      tabs.forEach(function (t, i) { t.addEventListener("click", function () { select(i); }); });
      list.addEventListener("keydown", function (e) {
        var i = tabs.indexOf(document.activeElement), n = tabs.length;
        var next = { ArrowRight: (i + 1) % n, ArrowLeft: (i - 1 + n) % n, Home: 0, End: n - 1 }[e.key];
        if (next === undefined || i < 0) return;
        e.preventDefault(); select(next);
      });
      new ResizeObserver(place).observe(list);
      place();
    });
  })();
</script>

With reduced motion: The underline jumps to the chosen tab instead of gliding.

Running cost: One measurement per change and a transform transition; a resize observer keeps it aligned.

  • Edit the `tabs` array to change labels and panel text; ids are used to link each tab to its panel.
  • Change the indicator colour from `bg-blue-600` (or `--ust-accent`) and its thickness from `h-0.5`.
  • Set the spacing between labels with `gap-6`; tighter gaps suit five or more tabs.
  • Slow the glide by raising `duration-300`; the indicator only moves with transform, so longer values stay smooth.

Full page for Underline Tabs With Sliding Indicator

Card Tabs With Content Panels

Product information for a woven wool blanket in folder-style tabs on a warm oatmeal page: Details, Materials, Care and Delivery. Unchosen tabs sit a little lower in a darker tone, and the chosen one turns white and joins the panel below it. Each panel has a sentence and three fact tiles.

<div class="ctp">
  <div class="ctp-list" role="tablist" aria-label="Product information">
    <button type="button" role="tab" id="ctp-t1" aria-controls="ctp-p1" aria-selected="true" tabindex="0">Details</button>
    <button type="button" role="tab" id="ctp-t2" aria-controls="ctp-p2" aria-selected="false" tabindex="-1">Materials</button>
    <button type="button" role="tab" id="ctp-t3" aria-controls="ctp-p3" aria-selected="false" tabindex="-1">Care</button>
    <button type="button" role="tab" id="ctp-t4" aria-controls="ctp-p4" aria-selected="false" tabindex="-1">Delivery</button>
  </div>
  <div class="ctp-panel" role="tabpanel" id="ctp-p1" aria-labelledby="ctp-t1" tabindex="0"><h3>Ettrick herringbone blanket</h3><p>A wool blanket woven on a 1950s loom in the Borders, finished with a hand-twisted fringe.</p><dl><div><dt>Size</dt><dd>140 × 200 cm</dd></div><div><dt>Weight</dt><dd>1.4 kg</dd></div><div><dt>Pattern</dt><dd>Herringbone</dd></div></dl></div>
  <div class="ctp-panel" role="tabpanel" id="ctp-p2" aria-labelledby="ctp-t2" tabindex="0" hidden><h3>Ettrick herringbone blanket</h3><p>Lambswool from two farms within 40 miles of the mill, spun and dyed on site.</p><dl><div><dt>Fibre</dt><dd>100% lambswool</dd></div><div><dt>Dye</dt><dd>Low-impact, azo-free</dd></div><div><dt>Origin</dt><dd>Scotland</dd></div></dl></div>
  <div class="ctp-panel" role="tabpanel" id="ctp-p3" aria-labelledby="ctp-t3" tabindex="0" hidden><h3>Ettrick herringbone blanket</h3><p>Air it outside rather than washing it. Spot clean with cold water and a wool soap.</p><dl><div><dt>Wash</dt><dd>Hand, 30°C max</dd></div><div><dt>Dry</dt><dd>Flat, in shade</dd></div><div><dt>Moths</dt><dd>Store with cedar</dd></div></dl></div>
  <div class="ctp-panel" role="tabpanel" id="ctp-p4" aria-labelledby="ctp-t4" tabindex="0" hidden><h3>Ettrick herringbone blanket</h3><p>Packed in a cotton bag and sent tracked. Free over $150, otherwise $9.</p><dl><div><dt>Dispatch</dt><dd>1 to 2 days</dd></div><div><dt>Returns</dt><dd>30 days</dd></div><div><dt>Carrier</dt><dd>Tracked post</dd></div></dl></div>
</div>
<style>
  .ctp { --ctp-accent: #0f766e; --ctp-tab: #e3dbcd; padding: 48px 16px; background: #efe9df; font-family: ui-sans-serif, system-ui, sans-serif; color: #1c1917; }
  .ctp > * { max-width: 42rem; margin-left: auto; margin-right: auto; }
  .ctp :focus-visible { outline: 2px solid var(--ctp-accent); outline-offset: 2px; }
  .ctp-list { display: flex; gap: 4px; overflow-x: auto; padding: 0 8px; }
  .ctp-list button { flex-shrink: 0; height: 44px; padding: 0 18px; border: 0; border-radius: 12px 12px 0 0; background: var(--ctp-tab); color: #44403c; font: 500 14px ui-sans-serif, system-ui, sans-serif; transform: translateY(4px); cursor: pointer; }
  .ctp-list button[aria-selected="true"] { position: relative; z-index: 1; background: #fff; color: #134e4a; transform: none; }
  .ctp-panel { padding: 28px; border-radius: 16px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
  .ctp-panel h3 { margin: 0; font: 400 24px ui-serif, Georgia, serif; }
  .ctp-panel p { margin: 12px 0 0; color: #57534e; line-height: 1.75; }
  .ctp-panel dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 24px 0 0; }
  .ctp-panel dl div { padding: 12px; border-radius: 12px; background: #f0fdfa; }
  .ctp-panel dt { font-size: 12px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: #115e59; }
  .ctp-panel dd { margin: 4px 0 0; font-size: 14px; font-weight: 600; }
</style>
<script>
  (function () {
    document.querySelectorAll(".ctp").forEach(function (root) {
      var tabs = Array.prototype.slice.call(root.querySelectorAll('[role="tab"]'));
      function select(i) {
        tabs.forEach(function (t, j) {
          t.setAttribute("aria-selected", i === j);
          t.tabIndex = i === j ? 0 : -1;
          root.querySelector("#" + t.getAttribute("aria-controls")).hidden = i !== j;
        });
        tabs[i].focus();
      }
      tabs.forEach(function (t, i) { t.addEventListener("click", function () { select(i); }); });
      root.querySelector(".ctp-list").addEventListener("keydown", function (e) {
        var i = tabs.indexOf(document.activeElement), n = tabs.length;
        var next = { ArrowRight: (i + 1) % n, ArrowLeft: (i - 1 + n) % n, Home: 0, End: n - 1 }[e.key];
        if (next === undefined || i < 0) return;
        e.preventDefault(); select(next);
      });
    });
  })();
</script>

With reduced motion: Nothing animates; the chosen tab simply joins the white panel.

Running cost: Plain colours and one small transform offset on the unchosen tabs; no transitions.

  • Change the page and unchosen tab colours, `bg-[#efe9df]` and `bg-[#e3dbcd]`, together so the tabs still read as behind the panel.
  • Edit `tabs`; each needs a `text` line and three `facts` for the tile row.
  • Remove `translate-y-1` from the unchosen tabs for a flatter, level row.

Segmented Pill Tabs for Switching Views

A dark race calendar for a trail running club with a three-way pill control: List, Map and Calendar. An amber pill slides under the chosen label, and each view shows the same three races in a different form, from rows with the total climb to a drawn map with start points to date tiles.

<div class="spt">
  <div class="spt-top">
    <h2>Upcoming races</h2>
    <div class="spt-list" role="tablist" aria-label="Race view">
      <span class="spt-pill" aria-hidden="true"></span>
      <button type="button" role="tab" id="spt-t0" aria-controls="spt-p0" aria-selected="true" tabindex="0">List</button>
      <button type="button" role="tab" id="spt-t1" aria-controls="spt-p1" aria-selected="false" tabindex="-1">Map</button>
      <button type="button" role="tab" id="spt-t2" aria-controls="spt-p2" aria-selected="false" tabindex="-1">Calendar</button>
    </div>
  </div>
  <div class="spt-panel" role="tabpanel" id="spt-p0" aria-labelledby="spt-t0" tabindex="0">
    <ul class="spt-rows">
      <li><div><b>Cobbler's Ridge 25K</b><small>Sat 8 Nov · Ashby Woods</small></div><span>740 m</span></li>
      <li><div><b>Lantern Night Trail 12K</b><small>Fri 21 Nov · Old Quarry</small></div><span>310 m</span></li>
      <li><div><b>Frostback Fell Race</b><small>Sun 7 Dec · High Cairn</small></div><span>1,120 m</span></li>
    </ul>
  </div>
  <div class="spt-panel" role="tabpanel" id="spt-p1" aria-labelledby="spt-t1" tabindex="0" hidden>
    <svg viewBox="0 0 400 210" role="img" aria-label="Map with three race starts marked"><path d="M0 150 C80 120 120 170 200 130 S330 80 400 110" fill="none" stroke="#44403c" stroke-width="18"/><circle cx="110" cy="70" r="6" fill="#fbbf24"/><circle cx="240" cy="120" r="6" fill="#fbbf24"/><circle cx="330" cy="55" r="6" fill="#fbbf24"/></svg>
  </div>
  <div class="spt-panel" role="tabpanel" id="spt-p2" aria-labelledby="spt-t2" tabindex="0" hidden>
    <ul class="spt-cal"><li><small>Sat</small><b>8</b><small>Nov</small></li><li><small>Fri</small><b>21</b><small>Nov</small></li><li><small>Sun</small><b>7</b><small>Dec</small></li></ul>
  </div>
</div>
<style>
  .spt { --spt-accent: #fbbf24; max-width: 36rem; width: calc(100% - 32px); box-sizing: border-box; margin: 40px auto; padding: 40px 20px; border-radius: 20px; background: #0c0a09; font-family: ui-sans-serif, system-ui, sans-serif; color: #f5f5f4; }
  .spt :focus-visible { outline: 2px solid #fde68a; outline-offset: 2px; }
  .spt-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
  .spt-top h2 { margin: 0; font-size: 18px; }
  .spt-list { position: relative; display: grid; grid-template-columns: repeat(3, 1fr); padding: 4px; border-radius: 999px; background: #292524; }
  .spt-pill { position: absolute; top: 4px; bottom: 4px; left: 4px; width: calc((100% - 8px) / 3); border-radius: 999px; background: var(--spt-accent); transition: transform .3s ease-out; }
  .spt-list button { position: relative; height: 40px; padding: 0 20px; border: 0; border-radius: 999px; background: none; color: #d6d3d1; font: 600 14px ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
  .spt-list button[aria-selected="true"] { color: #0c0a09; }
  .spt-panel { margin-top: 24px; border-radius: 16px; }
  .spt-panel svg { display: block; width: 100%; height: auto; border-radius: 16px; background: #1c1917; }
  .spt-rows, .spt-cal { margin: 0; padding: 0; list-style: none; border-radius: 16px; background: #1c1917; }
  .spt-rows li { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px; }
  .spt-rows li + li { border-top: 1px solid #292524; }
  .spt-rows b { display: block; font-weight: 500; }
  .spt-rows small { font-size: 14px; color: #a8a29e; }
  .spt-rows span { color: #fcd34d; font-size: 14px; }
  .spt-cal { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 16px; text-align: center; }
  .spt-cal li { padding: 12px; border-radius: 12px; background: #292524; }
  .spt-cal b { display: block; font-size: 24px; color: #fcd34d; }
  .spt-cal small { font-size: 12px; color: #d6d3d1; }
  @media (prefers-reduced-motion: reduce) { .spt-pill { transition: none; } }
</style>
<script>
  (function () {
    document.querySelectorAll(".spt").forEach(function (root) {
      var tabs = Array.prototype.slice.call(root.querySelectorAll('[role="tab"]')), pill = root.querySelector(".spt-pill");
      function select(i) {
        tabs.forEach(function (t, j) {
          t.setAttribute("aria-selected", i === j);
          t.tabIndex = i === j ? 0 : -1;
          root.querySelector("#" + t.getAttribute("aria-controls")).hidden = i !== j;
        });
        pill.style.transform = "translateX(" + i * 100 + "%)";
        tabs[i].focus();
      }
      tabs.forEach(function (t, i) { t.addEventListener("click", function () { select(i); }); });
      root.querySelector(".spt-list").addEventListener("keydown", function (e) {
        var i = tabs.indexOf(document.activeElement), n = tabs.length;
        var next = { ArrowRight: (i + 1) % n, ArrowLeft: (i - 1 + n) % n, Home: 0, End: n - 1 }[e.key];
        if (next === undefined || i < 0) return;
        e.preventDefault(); select(next);
      });
    });
  })();
</script>

With reduced motion: The amber pill jumps under the chosen label without sliding.

Running cost: A single pill moves with translateX by whole segment widths; no measuring is needed.

  • The pill width is one third of the track, `w-[calc((100%-0.5rem)/3)]`; change the 3 if you add or remove views.
  • Recolour the pill from `bg-amber-400` and the selected text from `text-stone-950`; keep strong contrast between them.
  • Edit `races` once and all three views update together.

Tabs With Count Badges

An issue tracker card with Open, In review and Closed tabs, each carrying a small rounded count. The chosen tab gets an indigo underline and a filled badge, and its panel lists issues with a coloured status dot and an issue number. Long titles truncate so rows stay one line on phones.

<div class="tcb">
  <div class="tcb-list" role="tablist" aria-label="Issues">
    <button type="button" role="tab" id="tcb-t1" aria-controls="tcb-p1" aria-selected="true" tabindex="0">Open <span>4<i> items</i></span></button>
    <button type="button" role="tab" id="tcb-t2" aria-controls="tcb-p2" aria-selected="false" tabindex="-1">In review <span>2<i> items</i></span></button>
    <button type="button" role="tab" id="tcb-t3" aria-controls="tcb-p3" aria-selected="false" tabindex="-1">Closed <span>3<i> items</i></span></button>
  </div>
  <div class="tcb-panel" role="tabpanel" id="tcb-p1" aria-labelledby="tcb-t1" tabindex="0"><ul>
    <li data-s="open">Checkout button hidden on small Android screens<code>#412</code></li>
    <li data-s="open">Invoice PDF shows the wrong VAT number<code>#405</code></li>
    <li data-s="open">Search ignores accented letters<code>#398</code></li>
    <li data-s="open">Reset link expires too quickly<code>#391</code></li>
  </ul></div>
  <div class="tcb-panel" role="tabpanel" id="tcb-p2" aria-labelledby="tcb-t2" tabindex="0" hidden><ul>
    <li data-s="review">Add Dutch translation to emails<code>#381</code></li>
    <li data-s="review">Cache product images for a week<code>#374</code></li>
  </ul></div>
  <div class="tcb-panel" role="tabpanel" id="tcb-p3" aria-labelledby="tcb-t3" tabindex="0" hidden><ul>
    <li>Dark mode for the dashboard<code>#350</code></li>
    <li>Export orders as CSV<code>#343</code></li>
    <li>Fix date picker in Safari<code>#336</code></li>
  </ul></div>
</div>
<style>
  .tcb { --tcb-accent: #4f46e5; width: calc(100% - 32px); max-width: 42rem; margin: 48px auto; overflow: hidden; border: 1px solid #e2e8f0; border-radius: 12px; background: #fff; font-family: ui-sans-serif, system-ui, sans-serif; color: #1e293b; }
  .tcb :focus-visible { outline: 2px solid var(--tcb-accent); outline-offset: -2px; }
  .tcb-list { display: flex; overflow-x: auto; padding: 0 8px; border-bottom: 1px solid #e2e8f0; }
  .tcb-list button { display: flex; flex-shrink: 0; align-items: center; gap: 8px; height: 48px; margin-bottom: -1px; padding: 0 12px; border: 0; border-bottom: 2px solid transparent; background: none; color: #475569; font: 500 14px ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
  .tcb-list button[aria-selected="true"] { border-color: var(--tcb-accent); color: #4338ca; }
  .tcb-list span { min-width: 24px; padding: 2px 6px; box-sizing: border-box; border-radius: 999px; background: #f1f5f9; color: #334155; font-size: 12px; font-weight: 600; }
  .tcb-list [aria-selected="true"] span { background: var(--tcb-accent); color: #fff; }
  .tcb-list i { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .tcb-panel ul { margin: 0; padding: 0; list-style: none; }
  .tcb-panel li { display: flex; align-items: center; gap: 12px; padding: 14px 20px; font-size: 14px; }
  .tcb-panel li + li { border-top: 1px solid #f1f5f9; }
  .tcb-panel li::before { content: ""; flex-shrink: 0; width: 10px; height: 10px; border-radius: 50%; background: #94a3b8; }
  .tcb-panel li[data-s="open"]::before { background: #10b981; }
  .tcb-panel li[data-s="review"]::before { background: #f59e0b; }
  .tcb-panel code { margin-left: auto; font-size: 12px; color: #475569; }
</style>
<script>
  (function () {
    document.querySelectorAll(".tcb").forEach(function (root) {
      var tabs = Array.prototype.slice.call(root.querySelectorAll('[role="tab"]'));
      function select(i) {
        tabs.forEach(function (t, j) {
          t.setAttribute("aria-selected", i === j);
          t.tabIndex = i === j ? 0 : -1;
          root.querySelector("#" + t.getAttribute("aria-controls")).hidden = i !== j;
        });
        tabs[i].focus();
      }
      tabs.forEach(function (t, i) { t.addEventListener("click", function () { select(i); }); });
      root.querySelector(".tcb-list").addEventListener("keydown", function (e) {
        var i = tabs.indexOf(document.activeElement), n = tabs.length;
        var next = { ArrowRight: (i + 1) % n, ArrowLeft: (i - 1 + n) % n, Home: 0, End: n - 1 }[e.key];
        if (next === undefined || i < 0) return;
        e.preventDefault(); select(next);
      });
    });
  })();
</script>

With reduced motion: Nothing animates; the underline and filled badge mark the chosen tab.

Running cost: Static styles only; the counts come from the list lengths, so there is nothing to keep in sync.

  • Counts are `t.items.length`; if you load data, pass a total from the server instead so the badge shows all items, not just the page.
  • Change the dot colours per status in the ternary on the `h-2.5 w-2.5` span.
  • Hide the badge when a count is zero by rendering it only when `t.items.length > 0`.

Vertical Tabs With Settings Panels

Account settings for a ceramics seller laid out as tabs down the left: Profile, Notifications, Billing and Security, each with a one-line hint. The chosen tab fills violet and its panel lists settings as label and value pairs with an edit button. On phones the tabs become a scrolling row above the panel and the hints are hidden.

<div class="vts">
  <div class="vts-list" role="tablist" aria-label="Account settings" aria-orientation="vertical">
    <button type="button" role="tab" id="vts-t1" aria-controls="vts-p1" aria-selected="true" tabindex="0"><b>Profile</b><small>Name, photo and bio</small></button>
    <button type="button" role="tab" id="vts-t2" aria-controls="vts-p2" aria-selected="false" tabindex="-1"><b>Notifications</b><small>Email and push</small></button>
    <button type="button" role="tab" id="vts-t3" aria-controls="vts-p3" aria-selected="false" tabindex="-1"><b>Billing</b><small>Plan and invoices</small></button>
    <button type="button" role="tab" id="vts-t4" aria-controls="vts-p4" aria-selected="false" tabindex="-1"><b>Security</b><small>Password and sign-in</small></button>
  </div>
  <div class="vts-panel" role="tabpanel" id="vts-p1" aria-labelledby="vts-t1" tabindex="0"><h3>Profile</h3><dl><div><dt>Display name</dt><dd>Rosa Achterberg</dd></div><div><dt>Studio</dt><dd>Achterberg Ceramics</dd></div><div><dt>Time zone</dt><dd>Amsterdam (UTC+1)</dd></div></dl></div>
  <div class="vts-panel" role="tabpanel" id="vts-p2" aria-labelledby="vts-t2" tabindex="0" hidden><h3>Notifications</h3><dl><div><dt>New orders</dt><dd>Email and push</dd></div><div><dt>Weekly summary</dt><dd>Mondays at 8:00</dd></div><div><dt>Product tips</dt><dd>Off</dd></div></dl></div>
  <div class="vts-panel" role="tabpanel" id="vts-p3" aria-labelledby="vts-t3" tabindex="0" hidden><h3>Billing</h3><dl><div><dt>Plan</dt><dd>Maker, $19 a month</dd></div><div><dt>Next invoice</dt><dd>1 December</dd></div><div><dt>Card</dt><dd>Visa ending 4421</dd></div></dl></div>
  <div class="vts-panel" role="tabpanel" id="vts-p4" aria-labelledby="vts-t4" tabindex="0" hidden><h3>Security</h3><dl><div><dt>Password</dt><dd>Changed 3 months ago</dd></div><div><dt>Two-step sign-in</dt><dd>On, authenticator app</dd></div><div><dt>Sessions</dt><dd>2 devices</dd></div></dl></div>
</div>
<style>
  .vts { --vts-accent: #7c3aed; display: flex; flex-direction: column; gap: 24px; width: calc(100% - 32px); max-width: 48rem; box-sizing: border-box; margin: 40px auto; padding: 16px; border: 1px solid #ede9fe; border-radius: 16px; background: #fff; font-family: ui-sans-serif, system-ui, sans-serif; color: #0f172a; }
  @media (min-width: 640px) { .vts { flex-direction: row; padding: 24px; } .vts-list { flex-direction: column; width: 224px; } .vts-list small { display: block !important; } }
  .vts :focus-visible { outline: 2px solid var(--vts-accent); outline-offset: 2px; }
  .vts-list { display: flex; flex-shrink: 0; gap: 4px; overflow-x: auto; }
  .vts-list button { flex-shrink: 0; padding: 10px 16px; border: 0; border-radius: 12px; background: none; color: #334155; text-align: left; font: inherit; cursor: pointer; }
  .vts-list button:hover { background: #f5f3ff; }
  .vts-list button[aria-selected="true"] { background: var(--vts-accent); color: #fff; }
  .vts-list b { display: block; font-size: 14px; }
  .vts-list small { display: none; font-size: 12px; color: #475569; }
  .vts-list [aria-selected="true"] small { color: #ede9fe; }
  .vts-panel { flex: 1; min-width: 0; border-radius: 12px; }
  .vts-panel h3 { margin: 0; font-size: 18px; }
  .vts-panel dl { margin: 16px 0 0; border-top: 1px solid #f1f5f9; }
  .vts-panel dl div { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 14px 0; border-bottom: 1px solid #f1f5f9; font-size: 14px; }
  .vts-panel dt { color: #475569; }
  .vts-panel dd { margin: 0; font-weight: 500; }
</style>
<script>
  (function () {
    document.querySelectorAll(".vts").forEach(function (root) {
      var tabs = Array.prototype.slice.call(root.querySelectorAll('[role="tab"]'));
      function select(i) {
        tabs.forEach(function (t, j) {
          t.setAttribute("aria-selected", i === j);
          t.tabIndex = i === j ? 0 : -1;
          root.querySelector("#" + t.getAttribute("aria-controls")).hidden = i !== j;
        });
        tabs[i].focus();
      }
      tabs.forEach(function (t, i) { t.addEventListener("click", function () { select(i); }); });
      root.querySelector(".vts-list").addEventListener("keydown", function (e) {
        var i = tabs.indexOf(document.activeElement), n = tabs.length;
        var next = { ArrowDown: (i + 1) % n, ArrowRight: (i + 1) % n, ArrowUp: (i - 1 + n) % n, ArrowLeft: (i - 1 + n) % n, Home: 0, End: n - 1 }[e.key];
        if (next === undefined || i < 0) return;
        e.preventDefault(); select(next);
      });
    });
  })();
</script>

With reduced motion: Nothing animates; the violet fill on the chosen tab marks the change.

Running cost: No transitions; switching shows one small definition list and hides the others.

  • Add sections to `sections`; `rows` is a list of label and value pairs shown in a definition list.
  • Change the column width with `sm:w-56` if your section names are longer.
  • Swap `bg-violet-600` for a quieter `bg-violet-50 text-violet-900` if the filled tab feels too strong next to your page.

Performance notes

Switching a tab changes a few attributes and shows one panel, so the cost is the content you render inside it. The examples keep all panels in the page and hide the inactive ones, which makes switching instant; for heavy panels, render only the selected one and keep its tab state.

The sliding indicator measures the selected tab once per change and moves with a transform, so it never forces layout during the animation. A resize observer keeps it aligned when the tab labels wrap or fonts load, and it disconnects when the component unmounts.

Questions

What keyboard support do tabs need?

Left and Right arrows move between tabs in a horizontal list, Up and Down in a vertical one, Home and End jump to the first and last tab, and Tab moves out of the list into the panel. Only the selected tab is in the tab order; the others have tabindex minus one.

Should arrow keys select a tab or only focus it?

Selecting on focus is simplest and fine when panels show instantly, which is the case here. If a panel loads data or is expensive to show, move focus with the arrows and select with Enter or Space instead.

Can I build tabs with only CSS?

Radio buttons or :target can switch panels without script, but they do not give the tablist roles and arrow-key behaviour screen reader users expect. Use the CSS-only route for simple decorative switches and the scripted pattern for real interface tabs.

How do I make Tailwind tabs scroll on small screens?

Let the tablist overflow horizontally with overflow-x-auto and keep labels on one line with whitespace-nowrap. Scroll the selected tab into view when it changes so it is never hidden past the edge.

Do tabs hurt SEO when content is hidden?

Content in hidden panels is still in the page and can be indexed, though search engines may weigh it less than visible text. Keep the most important copy in the first, selected panel.

Also in the gallery: React Tabs with Sliding Underline, Segmented Pills, Vertical and Icon Count Variants, CSS Tabs Collection with Radio, :target and Accessible ARIA Tabs in Six Styles, Page Tabs With Gliding Underline and Rising Content.

More collections: React Sidebar Components With Tailwind, Stepper Components for Multi-Step Forms, Hamburger Menu in HTML and CSS: 5 Menus to Copy. All tabs and navigation. Build your site free to have a full site built around them.

Product

Who It's For

Features

Resources

Company

View Sitemap