HTML/CSS custom radio button
- Last updated: Nov 3, 2023
- Views: 237
- Author: Admin

Hello colleagues.
Today we will analyze how you can style a checkbox switch using pure html and css without using javascript code.
HTML Code:
<body>
<input type="radio" class="radio-button" label="Radio 1" name="radio_btn" checked>
<input type="radio" class="radio-button" label="Radio 2" name="radio_btn">
</body>
CSS Code:
*{
margin: 0;
padding: 0;
font-family: "Montserrat", sans-serif;
}
body{
background-color: #2d3436;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
gap: 40px;
}
.radio-button{
appearance: none;
border: 1px solid #D1D5D8;
padding: 20px 30px;
border-radius: 2px;
display: flex;
align-items: center;
cursor: pointer;
gap: 10px;
}
.radio-button::before{
content: "";
background-color: #D1D5D8;
width: 20px;
height: 20px;
border-radius: 50%;
box-sizing: border-box;
transition: border .1s linear;
}
.radio-button::after{
content: attr(label);
color: #D1D5D8;
font-size: 22px;
text-transform: uppercase;
font-weight: 500;
}
.radio-button:checked{
background-color: #3498DB;
border-color: #3498DB;
}
.radio-button:checked::before{
border: 4px solid #D1D5D8;
background-color: #3498DB;
}
Thank you all, I hope my article was of some help to you.