Ask any question about CSS here... and get an instant response.
Post this Question & Answer:
How can I create a custom checkbox design using only CSS?
Asked on Apr 14, 2026
Answer
Creating a custom checkbox design using only CSS involves hiding the default checkbox and styling a label element to act as the checkbox. This approach allows you to have full control over the appearance of the checkbox.
<!-- BEGIN COPY / PASTE -->
<label class="custom-checkbox">
<input type="checkbox">
<span class="checkmark"></span>
</label>
<style>
.custom-checkbox {
display: inline-block;
position: relative;
cursor: pointer;
user-select: none;
}
.custom-checkbox input {
position: absolute;
opacity: 0;
cursor: pointer;
}
.checkmark {
width: 20px;
height: 20px;
background-color: #eee;
border-radius: 4px;
display: inline-block;
transition: background-color 0.3s;
}
.custom-checkbox input:checked + .checkmark {
background-color: #2196F3;
}
.checkmark:after {
content: "";
position: absolute;
display: none;
}
.custom-checkbox input:checked + .checkmark:after {
display: block;
}
.custom-checkbox .checkmark:after {
left: 7px;
top: 3px;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
transform: rotate(45deg);
}
</style>
<!-- END COPY / PASTE -->Additional Comment:
- The input element is hidden using opacity and absolute positioning.
- The checkmark is styled using a span that follows the input.
- CSS pseudo-elements (:after) are used to create the checkmark icon when checked.
- Transitions are applied for smooth visual effects when the checkbox state changes.
Recommended Links:
