I am just wondering how to use the new HTML5 input attribute “required” in the right way on radio buttons. Does every radio button field need the attribute like below or is it sufficient if only one field gets it?
<input type="radio" name="color" value="black" required="required" />
<input type="radio" name="color" value="white" required="required" />
TL;DR: Set the
requiredattribute for at least one input of the radio group.Setting
requiredfor all inputs is more clear, but not necessary (unless dynamically generating radio-buttons).To group radio buttons they must all have the same
namevalue. This allows only one to be selected at a time and appliesrequiredto the whole group.Also take note of:
Source