Custom Styled Radio Input with Larger Checked Dot
Here's how to create a custom-styled radio input with a custom color and a larger dot when checked using HTML and CSS:
HTML Structure
<div class="custom-radio">
<input type="radio" id="option1" name="radio-group">
<label for="option1">Option 1</label>
<input type="radio" id="option2" name="radio-group">
<label for="option2">Option 2</label>
<input type="radio" id="option3" name="radio-group">
<label for="option3">Option 3</label>
</div>
CSS Styling
.custom-radio {
display: flex;
flex-direction: column;
gap: 12px;
font-family: Arial, sans-serif;
}
.custom-radio input[type="radio"] {
/* Hide the default radio */
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
width: 0;
height: 0;
position: absolute;
opacity: 0;
}
.custom-radio label {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
position: relative;
padding-left: 28px;
}
/* Custom radio circle */
.custom-radio label::before {
content: "";
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 20px;
height: 20px;
border: 2px solid #ccc;
border-radius: 50%;
background-color: white;
transition: all 0.3s ease;
}
/* Custom radio dot (hidden by default) */
.custom-radio label::after {
content: "";
position: absolute;
left: 5px;
top: 50%;
transform: translateY(-50%) scale(0);
width: 10px;
height: 10px;
border-radius: 50%;
background-color: #4CAF50; /* Custom color - change this */
transition: all 0.3s ease;
}
/* When radio is checked */
.custom-radio input[type="radio"]:checked + label::before {
border-color: #4CAF50; /* Same as dot color */
}
.custom-radio input[type="radio"]:checked + label::after {
transform: translateY(-50%) scale(1.5); /* Makes the dot bigger */
}
/* Hover effect */
.custom-radio label:hover::before {
border-color: #4CAF50;
}
Customization Options
- Change the color: Replace
#4CAF50 with your preferred color (hex, rgb, or hsl)
- Adjust dot size: Modify the
scale(1.5) value in the :checked + label::after rule
- Change circle size: Adjust the
width and height in the label::before rule
- Change dot size: Adjust the
width and height in the label::after rule
Example with Different Colors
/* For option 1 */
#option1:checked + label::after,
#option1:checked + label::before {
border-color: #FF5722;
}
#option1:checked + label::after {
background-color: #FF5722;
}
/* For option 2 */
#option2:checked + label::after,
#option2:checked + label::before {
border-color: #2196F3;
}
#option2:checked + label::after {
background-color: #2196F3;
}
/* For option 3 */
#option3:checked + label::after,
#option3:checked + label::before {
border-color: #9C27B0;
}
#option3:checked + label::after {
background-color: #9C27B0;
}
This implementation is accessible (works with keyboard navigation), responsive, and maintains all the functionality of native radio buttons while providing a custom look.