How to style radio buttons and checkboxes

In this example, we will style radio buttons and checkboxes using CSS to enhance their appearance and make them more visually appealing. The following code demonstrates how to achieve this with simple CSS styling.

styling radio buttons, styling checkboxes, CSS custom styles, form elements design
Learn how to style radio buttons and checkboxes using CSS for a modern and attractive form design.
<style> /* Hide the default radio button */ input[type="radio"], input[type="checkbox"] { display: none; } /* Create custom radio button styles */ .custom-radio { display: inline-block; width: 20px; height: 20px; border-radius: 50%; border: 2px solid #007bff; position: relative; margin-right: 10px; cursor: pointer; } /* Style for the checked radio button */ input[type="radio"]:checked + .custom-radio { background-color: #007bff; } /* Create custom checkbox styles */ .custom-checkbox { display: inline-block; width: 20px; height: 20px; border: 2px solid #007bff; position: relative; margin-right: 10px; cursor: pointer; } /* Style for the checked checkbox */ input[type="checkbox"]:checked + .custom-checkbox { background-color: #007bff; } </style> <form> <label> <input type="radio" name="options" value="1"> <span class="custom-radio"></span> Option 1 </label> <label> <input type="radio" name="options" value="2"> <span class="custom-radio"></span> Option 2 </label> <label> <input type="checkbox" name="check1"> <span class="custom-checkbox"></span> Checkbox 1 </label> <label> <input type="checkbox" name="check2"> <span class="custom-checkbox"></span> Checkbox 2 </label> </form>

styling radio buttons styling checkboxes CSS custom styles form elements design