Skip to content

Instantly share code, notes, and snippets.

Created Jan 9, 2019
What would you like to do?
Pure CSS tabs
<div data-tabs class="tabs">
<div class="tab">
<input type="radio" name="tabgroup" id="tab-1" checked>
<label for="tab-1">Tab 1</label>
<div class="tab__content">
<h4>Tab heading 1</h4>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Incidunt libero ipsum, veniam magni modi exercitationem debitis ducimus assumenda ratione corporis, illum eius, laborum tempore cumque amet id perspiciatis nostrum unde?</p>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Ipsum, maiores.</p>
<div class="tab">
<input type="radio" name="tabgroup" id="tab-2">
<label for="tab-2">Tab 2</label>
<div class="tab__content">
<h4>Tab heading 2</h4>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Consectetur odio cum eveniet excepturi eum provident molestias ad ipsa unde dignissimos illo porro animi earum aliquam perspiciatis id omnis, adipisci incidunt. Qui, beatae. Beatae animi totam obcaecati at quae, iste facere fuga nemo pariatur esse nihil?</p>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Doloremque commodi eos voluptatem numquam pariatur deleniti repellat fugiat eligendi nulla molestiae sunt praesentium vero sequi distinctio error quibusdam maiores natus magnam, explicabo hic sed alias dolores, quis eum! Reprehenderit atque cupiditate dolorum? Saepe, doloribus veniam? Nulla!</p>
<div class="tab">
<input type="radio" name="tabgroup" id="tab-3">
<label for="tab-3">Tab 3</label>
<div class="tab__content">
<h4>Tab heading 3</h4>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Laboriosam officiis voluptas maiores deserunt ullam aliquam?</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusamus, officia accusantium quod fuga porro eius animi earum excepturi omnis! Reprehenderit!</p>
<div class="tab">
<input type="radio" name="tabgroup" id="tab-4">
<label for="tab-4">Tab 4</label>
<div class="tab__content">
<h4>Tab heading 4</h4>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Officia exercitationem veritatis vero eaque. Nam totam dolorem sapiente ullam non sed nostrum praesentium voluptatem, ad quam libero deserunt nemo fuga hic repudiandae veritatis cupiditate, mollitia recusandae!</p>
(function($, document) {
// get tallest tab__content element
let height = -1;
$('.tab__content').each(function() {
height = height > $(this).outerHeight() ? height : $(this).outerHeight();
$(this).css('position', 'absolute');
// set height of tabs + top offset
$('[data-tabs]').css('min-height', height + 40 + 'px');
}(jQuery, document));
<script src=""></script>
@import url('');
body {
font-family: 'Open Sans', sans-serif;
background-color: #C2EABA;
padding-top: 50px;
line-height: 1.4;
font-size: 1.4em;
.tabs {
clear: both;
position: relative;
max-width: 650px;
margin: 0 auto;
/* you can either manually set a min-height here or do it via JS ---> */
.tab {
float: left;
.tab label {
margin-right: 20px;
position: relative;
top: 0;
cursor: pointer;
color: #333;
text-transform: uppercase;
.tab [type=radio] {
display: none;
.tab__content {
position: relative;
top: 40px;
left: 0;
right: 0;
bottom: 0;
transition: opacity .2s cubic-bezier(.42,0,.34,1.01);
opacity: 0;
[type=radio]:checked ~ label {
border-bottom: 2px solid #1d1d1d;
color: #1d1d1d;
z-index: 2;
[type=radio]:checked ~ label ~ .tab__content {
z-index: 1;
opacity: 1;

This comment has been minimized.

Copy link

@zee-design zee-design commented Mar 15, 2020

Hi there!
Is there a chance you could review the code. I am in search of this kind of tabbed layout and I was very happy when I found your example, but unfortunately, it does not work anymore. The tabs are vertical and not horizontal anymore. I checked many other versions and there seem to be an issue with tabs. Too many floated elements, content sliding under floated elements in mobile view, etc...
Your version is the cleanest I found and would like to use as a starter for my portfolio piece.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment