Pure CSS Tabs
Working tabs with panels and no JavaScript, powered by radio buttons and :has().
<div class="tabs">
<div class="tab-list">
<label><input type="radio" name="tab" checked>Overview</label>
<label><input type="radio" name="tab">Specs</label>
<label><input type="radio" name="tab">Reviews</label>
</div>
<div class="tab-panels">
<div>A quick overview of the product.</div>
<div>Dimensions, materials and more.</div>
<div>4.8 out of 5 from 120 reviews.</div>
</div>
</div>
.tabs {
width: 280px;
font: 14px/1.5 system-ui, sans-serif;
}
.tab-list {
display: flex;
gap: 4px;
border-bottom: 1px solid #e5e7eb;
}
.tab-list label {
margin-bottom: -1px;
padding: 10px 14px;
color: #6b7280;
font-weight: 600;
cursor: pointer;
}
.tab-list input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.tab-list label:has(input:checked) {
color: #111;
box-shadow: inset 0 -2px 0 #6366f1;
}
.tab-list label:has(input:focus-visible) {
border-radius: 6px;
outline: 2px solid #6366f1;
}
.tab-panels > div {
display: none;
padding: 14px 2px;
color: #374151;
}
.tabs:has(label:nth-child(1) input:checked) .tab-panels > :nth-child(1),
.tabs:has(label:nth-child(2) input:checked) .tab-panels > :nth-child(2),
.tabs:has(label:nth-child(3) input:checked) .tab-panels > :nth-child(3) {
display: block;
}
About this CSS Tabs
This CSS Tabs is 46 lines of pure CSS (0.8 KB) with no JavaScript and no dependencies. It uses box shadows, Flexbox, the :has() selector and the :checked state (no JavaScript). It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
- box shadows
- Flexbox
- the :has() selectorChrome 105+, Safari 15.4+, Firefox 121+.
- the :checked state (no JavaScript)
- keyboard focus styles
Customize it
The colors in this snippet. Search and replace them to match your brand:
#e5e7eb#6b7280#111#6366f1#374151
How to use this pure css tabs
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.tabsclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.