Tabs
tabbed navigation component for multiple panelsA tabbed navigation component that allows users to switch between different content panels. This component works entirely without JavaScript, using CSS and HTML radio buttons to manage the active tab state.
How It Works
The tab system uses HTML radio buttons with the same name attribute to ensure only one tab can be selected at a time. CSS :checked pseudo-selectors show the corresponding content panel when a tab is selected.
Basic Usage
1 | |
Dynamic Tab Generation
For dynamic content, you can use template loops to generate tabs:
1 | |
Container
<div class="tabs">: The main container that holds all tab elements
Tab Pattern
Each tab consists of three elements that must appear in this order:
Radio Input:
<input name="tab-group" type="radio" id="tab-id" class="input"/>- Controls which tab is active
- All tabs in a group must share the same
nameattribute - Each tab needs a unique
id
Tab Label:
<label for="tab-id" class="label">Tab Title</label>- The clickable tab header
forattribute must match the radio input’sid
Content Panel:
<div class="panel">Content here</div>- Contains the tab’s content
- Shown when the corresponding radio button is checked
Important Notes
- Consistent Naming: All radio inputs in a tab group must have the same
nameattribute - Unique IDs: Each radio input must have a unique
id - Matching Labels: Each label’s
forattribute must match its radio input’sid - Order Matters: The input, label, and panel must appear in that exact order for CSS to work correctly