Pure CSS radio and checkbox inputs
by Jasper Stevens
HTML
<h1>Pure CSS radio and checkbox inputs</h1>
<form>
<div class="input-row">
<input id="radio-input-1" type="radio" value="myValue 1" name="radio-group" checked>
<label for="radio-input-1" class="input-helper input-helper--radio">myValue 1</label>
<br>
<input id="radio-input-2" type="radio" value="myValue 2" name="radio-group">
<label for="radio-input-2" class="input-helper input-helper--radio">myValue 2</label>
</div>
<div class="input-row">
<input id="checkbox-input-1" type="checkbox" value="myValue 1" checked>
<label for="checkbox-input-1" class="input-helper input-helper--checkbox">myValue 1</label>
<br>
<input id="checkbox-input-2" type="checkbox" value="myValue 2">
<label for="checkbox-input-2" class="input-helper input-helper--checkbox">myValue 2</label>
</div>
</form>
CSS
body {
padding: 2em;
font-family: 'Helvetica Neue', Arial, sans-serif;
font-size: 1em;
line-height: 1.2em;
}
h1 {
margin-bottom: 1em;
line-height: 1.3em;
}
.input-row {
margin-bottom: 20px;
}
.input-helper {
position: relative;
display: inline-block;
margin-bottom: 5px;
}
.input-helper:before {
content: '';
display: block;
position: absolute;
}
.input-helper--radio {
padding-left: 18px;
}
.input-helper--radio:before {
top: 3px;
left: 0;
width: 10px;
height: 10px;
border-radius: 50%;
border: 1px solid #222;
}
.input-helper--checkbox {
padding-left: 20px;
}
.input-helper--checkbox:before {
top: 2px;
left: 0;
width: 13px;
height: 13px;
border: 1px solid #222;
}
input[type="radio"] {
display: none;
}
input[type="radio"]:checked + label:before {
background: #00ff00;
}
input[type="checkbox"] {
display: none;
}
input[type="checkbox"]:checked + label:before {
background: #ff0000;
}