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> </div>
2. Apply styles to create the tabbed interface. CSS will handle the layout, appearance, and transitions for the tabs and their associated content.
*,*:after,*:before{box-sizing:border-box;} #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:after, #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; margin-bottom:-1px; background:#333; } .tab-content { color: #fff; background:#888; font-family: arial; font-weight: bold; padding: 0 10px; width: 100%; float: left; height: 0em; overflow: hidden; transition: 0.5s; } input[type="radio"]:checked+label{background:#888} #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.
Similar Code Snippets:
I code and create web elements for amazing people around the world. I like work with new people. New people new Experiences.
I truly enjoy what I’m doing, which makes me more passionate about web development and coding. I am always ready to do challenging tasks whether it is about creating a custom CMS from scratch or customizing an existing system.