In this tutorial, we style Radio Buttons and Checkboxes with pure CSS; CSS3 to be specific and without the use of images.
Styling them have become possible with the introduction of CSS3 and the
:checked pseudo-class selector.
Let’s Do this
This method is exactly the same for styling both radio buttons and checkboxes… So, let’s do this.
We will use the following basic HTML:
<input type="radio" />
label needs to be connected to the
input using the
for=" " and
id=" ". For ease of styling, we will wrap the
label and 'radio button group'within
Final mark up for our radio button group looks like below:
Let’s get styling…. To begin, we will:
1. Hide the checkbox element:
2. Then we style the
span tag within the label as required:
- display inline
- set dimensions and placement (height, width, paddings, margins)
- tweak positioning (vertical alignment)
- style the cursor
It’s basically plain CSS/SCSS, so feel free to customise as desired
3. Finally, we style the
:before pseudo-class selector of the ‘checked’ input item to add visual indicators.
Styled Radio buttons and Checkboxes, achieved with CSS Only (no images), using the
:checked pseudo-class selector and
+ sibling – cool huh?
Radio buttons and Checkboxes, are indispensable in web design, but until recently, have been very difficult to style. The CSS3 method described above, which is applicable to both Radio buttons and Checkboxes allows us to style them by using the
:checked pseudo selector and
+ sibling selector.
Hopefully this will come in handy for your next project.