I was shown that in general, there are two ways of labeling radio buttons:
Method #1:
<label>Male<input type="radio" name="gender" value="m"></label>
<label>Female<input type="radio" name="gender" value="f"></label>
Method #2 (using for):
<label for="id_male">Male</label>
<input type="radio" id="id_male" name="gender" value="m">
<label for="id_female">Female</label>
<input type="radio" id="id_female" name="gender" value="f">
But what if there is a need to associate a group of radio buttons with a label?
i.e:
<label>What is your gender?
<label>Male<input type="radio" name="gender" value="m"></label>
<label>Female<input type="radio" name="gender" value="f"></label>
</label>
The questions are:
Is the way used to associate the "What is your gender?" label above correct?
Is there a way to associate "What is your gender?" that corresponds to Method #2 (i.e. using for)?
use method #2 like this:
<form action="" method="post">
<fieldset>
<legend>What's your gender?</legend>
<label for="id_male">Male</label>
<input type="radio" id="id_male" name="gender" value="m">
<label for="id_female">Female</label>
<input type="radio" id="id_female" name="gender" value="f">
</fieldset>
</form>
See more about fieldset
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With