name attribute in an HTML form?Radio buttons with the same name attribute form a group where only one option can be selected at a time. Selecting another option deselects the previous one.
The correct way is to use <input type="checkbox"> and a <label> with a matching for attribute to the input's id.
<form> <input type="radio" name="color" id="red" value="red"> <label for="red">Red</label> <input type="radio" name="color" id="blue" value="blue"> <label for="blue">Blue</label> </form>
The code creates two radio buttons with the same name, so the user can select only one color at a time.
The best practice is to use <label> with a matching for attribute to the input's id. This ensures screen readers correctly announce the label and makes the label text clickable for better usability.
The :checked pseudo-class selects checked checkboxes. The syntax must be input[type="checkbox"]:checked.
