Underline Tabs
A keyboard-accessible tab strip with the active tab underlined.
6 frameworksIntermediate
Pill tabs above a raised, bordered card panel.
<!-- Pill tabs above a raised card panel: the switch reads as swapping the contents of one card. -->
<div class="max-w-2xl" data-tabs-card>
<div class="mb-3 flex max-w-full gap-1 overflow-x-auto" role="tablist" aria-label="Product details">
<button class="whitespace-nowrap rounded-lg px-3 py-1.5 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-100 hover:text-gray-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 motion-reduce:transition-none aria-selected:bg-blue-50 aria-selected:text-blue-700 dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-gray-100 dark:focus-visible:ring-blue-400 dark:aria-selected:bg-blue-950 dark:aria-selected:text-blue-300" type="button" role="tab" id="cd-shipping" aria-controls="cd-panel-shipping" aria-selected="true" tabindex="0">Shipping</button>
<button class="whitespace-nowrap rounded-lg px-3 py-1.5 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-100 hover:text-gray-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 motion-reduce:transition-none aria-selected:bg-blue-50 aria-selected:text-blue-700 dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-gray-100 dark:focus-visible:ring-blue-400 dark:aria-selected:bg-blue-950 dark:aria-selected:text-blue-300" type="button" role="tab" id="cd-returns" aria-controls="cd-panel-returns" aria-selected="false" tabindex="-1">Returns</button>
<button class="whitespace-nowrap rounded-lg px-3 py-1.5 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-100 hover:text-gray-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 motion-reduce:transition-none aria-selected:bg-blue-50 aria-selected:text-blue-700 dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-gray-100 dark:focus-visible:ring-blue-400 dark:aria-selected:bg-blue-950 dark:aria-selected:text-blue-300" type="button" role="tab" id="cd-warranty" aria-controls="cd-panel-warranty" aria-selected="false" tabindex="-1">Warranty</button>
</div>
<div class="rounded-xl border border-gray-200 bg-white p-5 text-sm leading-relaxed text-gray-600 shadow-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 dark:border-gray-800 dark:bg-gray-900 dark:text-gray-300 dark:focus-visible:ring-blue-400" role="tabpanel" id="cd-panel-shipping" aria-labelledby="cd-shipping" tabindex="0"><p>Free two-day shipping on orders over $50, tracked end to end.</p></div>
<div class="rounded-xl border border-gray-200 bg-white p-5 text-sm leading-relaxed text-gray-600 shadow-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 dark:border-gray-800 dark:bg-gray-900 dark:text-gray-300 dark:focus-visible:ring-blue-400" role="tabpanel" id="cd-panel-returns" aria-labelledby="cd-returns" tabindex="0" hidden><p>30-day returns, prepaid label, refunded within three business days.</p></div>
<div class="rounded-xl border border-gray-200 bg-white p-5 text-sm leading-relaxed text-gray-600 shadow-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 dark:border-gray-800 dark:bg-gray-900 dark:text-gray-300 dark:focus-visible:ring-blue-400" role="tabpanel" id="cd-panel-warranty" aria-labelledby="cd-warranty" tabindex="0" hidden><p>Two-year limited warranty covering manufacturing defects.</p></div>
</div>
<script>
(function () {
document.querySelectorAll('[data-tabs-card]').forEach(function (root) {
var tabs = [].slice.call(root.querySelectorAll('[role="tab"]'));
function panelFor(t) { return document.getElementById(t.getAttribute('aria-controls')); }
function select(i, focus) {
tabs.forEach(function (t, n) {
var on = n === i;
t.setAttribute('aria-selected', String(on));
t.tabIndex = on ? 0 : -1;
var p = panelFor(t);
if (p) p.hidden = !on;
});
if (focus) tabs[i].focus();
}
tabs.forEach(function (t, i) {
t.addEventListener('click', function () { select(i, false); });
t.addEventListener('keydown', function (e) {
var n = -1;
if (e.key === 'ArrowRight') n = (i + 1) % tabs.length;
else if (e.key === 'ArrowLeft') n = (i - 1 + tabs.length) % tabs.length;
else if (e.key === 'Home') n = 0;
else if (e.key === 'End') n = tabs.length - 1;
else return;
e.preventDefault();
select(n, true);
});
});
});
})();
</script>| Prop | Type | Default | Description |
|---|---|---|---|
itemsrequired | TabItem[] | - | The array of items to render. |
defaultTabId | string | - | Id of the item expanded on mount. |
onSelect | (id: string) => void | - | Fired with the menu item the user chose. |
className | string | - | Additional classes merged onto the root element. |
The panel is a bordered, shadowed surface, so the switch reads as swapping the contents of one card rather than editing loose prose. Match the panel `border` and `bg` across light and dark, and keep the tab gap above the card so the two never touch.