Skip to content

Instantly share code, notes, and snippets.

@brickbones
Created August 6, 2020 18:26
Show Gist options
  • Save brickbones/0b447985b10f143a160bcf2e1d69726a to your computer and use it in GitHub Desktop.
Save brickbones/0b447985b10f143a160bcf2e1d69726a to your computer and use it in GitHub Desktop.
Tabs with only HTML and CSS
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<title>Tabs</title>
</head>
<body>
<div class="mytabs">
<input type="radio" id="tabfree" name="mytabs" checked="checked">
<label for="tabfree">Free</label>
<div class="tab">
<h2>Free</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<input type="radio" id="tabsilver" name="mytabs">
<label for="tabsilver">Silver</label>
<div class="tab">
<h2>Silver</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
</div>
<input type="radio" id="tabgold" name="mytabs">
<label for="tabgold">Gold</label>
<div class="tab">
<h2>Gold</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
</div>
</div>
</body>
</html>
<style>
body {
background: #ccc;
font-family: 'Roboto', sans-serif;
}
.mytabs {
display: flex;
flex-wrap: wrap;
max-width: 600px;
margin: 50px auto;
padding: 25px;
}
.mytabs input[type="radio"] {
display: none;
}
.mytabs label {
padding: 25px;
background: #e2e2e2;
font-weight: bold;
}
.mytabs .tab {
width: 100%;
padding: 20px;
background: #fff;
order: 1;
display: none;
}
.mytabs .tab h2 {
font-size: 3em;
}
.mytabs input[type='radio']:checked + label + .tab {
display: block;
}
.mytabs input[type="radio"]:checked + label {
background: #fff;
}
</style>
@HenryTurbedsky
Copy link

👍

@khanhndhe153638
Copy link

you are so cool

@roykamsi
Copy link

Thank you!

@Hemalatha1504
Copy link

Thank you so much

@jakariashakib
Copy link

thanks bro

@developers15
Copy link

i LIKE TURTKES

@Vichai007
Copy link

Thank you very much. This is very helpful.
If I add the button (below) to the tab id tabfree, and I want it to display the tab id tabsilver, what js code should be in function goToNextTab()? Thanks.

NextTab

@asmallick1999
Copy link

thank you

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