How To Build Tabs only with CSS

Allen Kim
Digital-Heart
Published in
3 min readMar 15, 2019

--

There are several ways to provide navigation on a web site. Tabbed navigation is one of them; menu, sidebar, etc.

The key of implementing tabs without Javascript is to use radio buttons.

  1. We connect radio buttons with labels.
  2. When label is clicked, only one radio button is checked as selected.
  3. Only matching contents of selected radio button is visible.

Let’s code.

1. Code HTML for tab buttons

We will have input tags with type radio and with the same name as tabs by only making id differently, followed by label tags with attribute for matching to the radio input tag id.

<input type="radio" name="tabs" id="tab1" checked />
<label for="tab1">Tab1</label>
<input type="radio" name="tabs" id="tab2" />
<label for="tab2">Tab2</label>
<input type="radio" name="tabs" id="tab3" />
<label for="tab3">Tab3</label>
<input type="radio" name="tabs" id="tab4" />
<label for="tab4">tab4</label>
<input type="radio" name="tabs" id="tab5" />
<label…

--

--