# Pure CSS Tabs

> Working tabs with panels and no JavaScript, powered by radio buttons and :has().

- Category: [CSS Navigation](https://copy-css.com/category/navigation)
- Tags: tabs, radio, has, panels, no javascript
- Live preview: https://copy-css.com/snippets/css-tabs
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<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>
```

## CSS

```css
.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;
}
```

## Notes

- 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).
- the :has() selector: Chrome 105+, Safari 15.4+, Firefox 121+.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
