Notes
HTML
CSS
JS
Tools
Code Snippets
HTML Entity
About
Contact Us
Simple radio button using HTML and CSS
HTML
CSS
JS
Output
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- bootstrap 5 CDN and css --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" integrity="sha512-Fo3rlrZj/k7ujTnHg4CGR2D7kSs0v4LLanw2qksYuRlEzO+tcaEPQogQ0KaoGN26/zrn20ImR1DfuLWnOo7aBA==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> <!-- google font and font awesome CDN --> <link href="https://fonts.googleapis.com/css2?family=Manrope:wght@200;300;400;500;600;700;800&family=Roboto&display=swap" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" integrity="sha512-Fo3rlrZj/k7ujTnHg4CGR2D7kSs0v4LLanw2qksYuRlEzO+tcaEPQogQ0KaoGN26/zrn20ImR1DfuLWnOo7aBA==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <title>simple radio button using HTML CSS </title> </head> <body> <div class="row"> <div class="col-md-8 offset-md-2"> <h1 class="rangeSliderHeading text-center mt-5">Simple radio button using HTML and CSS</h1> <div class="mainDivRadio"> <div class="button-cover"> <div class="button r" id="button-1"> <input type="checkbox" class="checkbox" checked /> <div class="knobs"></div> <div class="layer"></div> </div> </div> </div> </div> </div> </body> </html>
Copied
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- bootstrap 5 CDN and css --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" integrity="sha512-Fo3rlrZj/k7ujTnHg4CGR2D7kSs0v4LLanw2qksYuRlEzO+tcaEPQogQ0KaoGN26/zrn20ImR1DfuLWnOo7aBA==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> <!-- google font and font awesome CDN --> <link href="https://fonts.googleapis.com/css2?family=Manrope:wght@200;300;400;500;600;700;800&family=Roboto&display=swap" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" integrity="sha512-Fo3rlrZj/k7ujTnHg4CGR2D7kSs0v4LLanw2qksYuRlEzO+tcaEPQogQ0KaoGN26/zrn20ImR1DfuLWnOo7aBA==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <title>simple radio button using HTML CSS </title> </head> <body> <div class="row"> <div class="col-md-8 offset-md-2"> <h1 class="rangeSliderHeading text-center mt-5">Simple radio button using HTML and CSS</h1> <div class="mainDivRadio"> <div class="button-cover"> <div class="button r" id="button-1"> <input type="checkbox" class="checkbox" checked /> <div class="knobs"></div> <div class="layer"></div> </div> </div> </div> </div> </div> </body> </html>
CSS
body{ overflow:hidden } .mainDivRadio { display: flex; justify-content: center; align-items: center; height: 100vh; } .rangeSliderHeading { color: rgb(6, 2, 114); } .knobs, .layer { position: absolute; top: 0; bottom: 0; left: 0; } .button { position: relative; width: 36px; height: 21px; overflow: hidden; } .button.r, .button.r .layer { border-radius: 100px; } .button.b2 { border-radius: 2px; } .checkbox { position: relative; width: 100%; height: 100%; padding: 0; margin: 0; opacity: 0; cursor: pointer; z-index: 3; } .knobs { z-index: 2; } .layer { width: 100%; background-color: #DFDFDF; transition: 0.3s ease all; z-index: 1; } /* Button 1 */ #button-1 .knobs:before { content: ""; position: absolute; top: 3px; left: 4px; width: 15px; height: 15px; font-weight: bold; text-align: center; line-height: 1; background-color: #ffffff; border-radius: 50%; transition: 0.3s cubic-bezier(0.18, 0.89, 0.35, 1.15) all; } #button-1 .checkbox:checked+.knobs:before { content: ""; left: 18px; background-color: #ffffff; } #button-1 .checkbox:checked~.layer { background-color: #0E6651; } #button-1 .knobs, #button-1 .knobs:before, #button-1 .layer { transition: 0.3s ease all; }
Copied
body{ overflow:hidden } .mainDivRadio { display: flex; justify-content: center; align-items: center; height: 100vh; } .rangeSliderHeading { color: rgb(6, 2, 114); } .knobs, .layer { position: absolute; top: 0; bottom: 0; left: 0; } .button { position: relative; width: 36px; height: 21px; overflow: hidden; } .button.r, .button.r .layer { border-radius: 100px; } .button.b2 { border-radius: 2px; } .checkbox { position: relative; width: 100%; height: 100%; padding: 0; margin: 0; opacity: 0; cursor: pointer; z-index: 3; } .knobs { z-index: 2; } .layer { width: 100%; background-color: #DFDFDF; transition: 0.3s ease all; z-index: 1; } /* Button 1 */ #button-1 .knobs:before { content: ""; position: absolute; top: 3px; left: 4px; width: 15px; height: 15px; font-weight: bold; text-align: center; line-height: 1; background-color: #ffffff; border-radius: 50%; transition: 0.3s cubic-bezier(0.18, 0.89, 0.35, 1.15) all; } #button-1 .checkbox:checked+.knobs:before { content: ""; left: 18px; background-color: #ffffff; } #button-1 .checkbox:checked~.layer { background-color: #0E6651; } #button-1 .knobs, #button-1 .knobs:before, #button-1 .layer { transition: 0.3s ease all; }
JS
Copied
Output
Our Courses
HTML 5
CSS
JavaScript
MySql
PHP
Laravel
Bootstrap
Programming Tutorial
PHP
JavaScript
HTML
Laravel
MySQL
JQuery
CSS
Git
Bootstrap
Vue JS
Android
Python
Server
Code Snippets
Chat Box
Range Slider
Radio Button
Select Box
Nav Bar
Other
Testimonial
Carousel
Logo
Loader
Lightbox
Forms
Popup
Table
HTML Course Code
HTML Entity
↑→ Arrows
$¢ Currency
Aö Letters
%+ Math
1¾ Numbers
&— Punctuation
©™ Symbols
Best Of
Internet
Technology
Health
Travel
Onine Tools
CSS Minifier
Text Converter
Age Calculator
Pincode Details
Whiteboard
PDF to Text
Gradient Generator
PX to REM Converter
REM to PX Converter
PX to EM Converter
EM to PX Converter
WEBP Converter
Latest & Upcoming movies
Bollywood
Hollywood
Tamil
Telgu
Bangla
Web Series
Notes
HTML
CSS
JS