HTML Tabs Using Radio Input and CSS

HTML Tabs Using Radio Input and CSS
Code Snippet:Tabs without Javascript using Radio Buttons
Author: Dave Noel
Published: March 4, 2024
Last Updated: March 4, 2024
Downloads: 1,075
License: MIT
Edit Code online: View on CodePen
Read More

This code creates HTML tabs using radio inputs and CSS. The tabs allow easy navigation between different content sections. The CSS styles enhance the visual appeal, with a gradient background and a shadow effect. Each radio input corresponds to a labeled tab, and selecting a tab reveals its associated content.

Moreover, the tabs smoothly transition in height, providing a clean and user-friendly interface. This code is helpful for organizing content and improving the overall user experience on a webpage.

How to Create Html Tabs Using Radio Input And Css

1. First, create the HTML structure for the tabs. Each tab will be represented by a radio input and a corresponding label. Additionally, create div elements to contain the content for each tab.

<div id="page-wrap">
  <input type="radio" name="tab" id="tab1" checked>
  <label class="" for="tab1">1</label>
  <input type="radio" name="tab" id="tab2">
  <label class="" for="tab2">2</label>
  <input type="radio" name="tab" id="tab3">
  <label class="" for="tab3">3</label>
  <div id="tab1tab" class="tab-content">This is tab 1!</div>
  <div id="tab2tab" class="tab-content">Whoah! Tab 2 here!</div>
  <div id="tab3tab" class="tab-content">Here's a tertiary tab!</div>

2. Apply styles to create the tabbed interface. CSS will handle the layout, appearance, and transitions for the tabs and their associated content.


#page-wrap {
  width: 450px;
  margin: 40px auto;
  box-shadow: 0 3px 5px #666;
  overflow: visible;
  float: left;
  background: #ebebeb;
  border-radius: 5px;
  position: relative;
  z-index: 1;

#page-wrap:before {
  content: "";
  width: 90%;
  position: absolute;
  height: 20px;
  box-shadow: 0 20px 20px #000;
  bottom: 25px;
  transform: rotate(5deg);
  z-index: -1;
  right: 5px

#page-wrap:after {
  transform: rotate(-5deg);
  left: 5px;

input[type="radio"] {
  position: absolute;
  left: -200%;

label {
  display: block;
  border-radius: 5px 5px 0 0;
  border: 1px solid #999;
  width: 80px;
  height: 40px;
  float: left;
  margin-right: 2px;
  text-align: center;
  line-height: 40px;
  color: #fff;
  font-family: arial;
  font-weight: bold;
  cursor: pointer;

.tab-content {
  color: #fff;
  font-family: arial;
  font-weight: bold;
  padding: 0 10px;
  width: 100%;
  float: left;
  height: 0em;
  overflow: hidden;
  transition: 0.5s;
#tab1:checked~#tab1tab {
  height: 150px;
  padding: 10px;

#tab2:checked~#tab2tab {
  height: 150px;
  padding: 10px;

#tab3:checked~#tab3tab {
  height: 150px;
  padding: 10px;

In this example, JavaScript isn’t necessary as the functionality is achieved purely with HTML and CSS. However, you may use JavaScript to enhance interactions or create dynamic content loading within each tab.

That’s all! hopefully, you have successfully created HTML tabs Using Radio Input and CSS. If you have any questions or suggestions, feel free to comment below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link