Search

Tabbed content

Tabbed content

Combining <label> and <input type=”radio”> can do magic! And all because when you click on a <label>, the browser will automatically pass the focus to its associated input. In case with the radio input, that means it will be checked. The layout is simple: we create several pairs of input-label elements and the related number of divs for content.

CSS has a native :checked selector for the checked inputs (both radios and checkboxes). And thanks to the ~ (tilde), which is officially called the subsequent-sibling combinator, we can toggle visibility of the content blocks. The only requirement is that content divs should be placed AFTER radio inputs.