🔘HTML input: radio
allowing the user to choose from one out of several options
Essentials
The <input>
field for type="radio"
looks like this:
Takeaways
Unlike
type="text"
eachtype="radio"
button must have the samename
if it belongs to a set of related options(we would have a different value for the
name
attribute if we have another set of related options elsewhere on the same form, as in the case withgender
)
The
value
attribute does not need to have the same value as the text in the<label>
i.e. the form will submit
"en"
even though the user may seeEnglish
on the form
The
<label>
corresponds with each radio button not via the button'sname
attribute but via theid
since that provides the unique identifier in this caseThe
<label>
also allows greater accessibility as a user can now click on the label instead of just the button itself!
Last updated