HTML Radio Button | |
A second type of input is the radio button. Radio buttons are used when you want users to be able to select one and only one of the options. Below is an example:
Code:
<input type="radio" name="color" value="red">Red<br>
<input type="radio" name="color" value="green">Green<br>
<input type="radio" name="color" value="blue">Blue<br>
In this case, the key is color, and the values can be either red, green, or blue, depending on the radio button selected.
If we want to pre-select a radio button, we'll specify "selected" at the end of the
<input> tag, such as follows:
<input type="radio" name="color" value="red" selected>Red<br>