I attempted to utilize input[type=radio]::after
, but it doesn't appear to be effective. However, I have discovered a neat little workaround that functions in all modern browsers:
Add a <span>
after each radio button, with no spaces in between. Although this span is positioned above the input, the input remains clickable due to pointer-events: none
(please note that this is not supported in older versions of IE).
You now have the ability to customize the buttons however you desire:
span.customRadio {
display: none;
}
input[type="radio"] {
width: 16px;
height: 16px;
margin: 0;
cursor: default;
}
input[type="radio"] + span.customRadio {
display: inline-block;
width: 16px;
height: 16px;
background-color: white;
margin: 0 0 0 -16px;
border-radius: 50%;
box-shadow: 0 0 3px -1px rgba(0, 0, 0, 0.8);
pointer-events: none;
}
input[type="radio"] + span.customRadio::after {
content: '.';
color: transparent;
position: absolute;
display: block;
width: 2px;
height: 2px;
margin: 7px 0 0 7px;
opacity: 0.6;
border-radius: 50%;
transition: .2s;
}
input[type="radio"]:checked + span.customRadio::after {
width: 10px;
height: 10px;
margin: 3px 0 0 3px;
opacity: 1;
background-color: #3388ff;
box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.2);
}
<input name="test" type="radio" checked="checked"><span class="customRadio"></span>
<input name="test2" type="radio"><span class="customRadio"></span><br><br>
See it in action:<br>
<input name="test3" type="radio"><span class="customRadio"></span>
<input name="test3" type="radio"><span class="customRadio"></span>
<input name="test3" type="radio"><span class="customRadio"></span>
JSFiddle