html · level 2 · unit 2 · lesson 1
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Radio buttons that share a name let you pick only one.
type="radio" makes a : a small circle to pick. It is named after the buttons on old car radios, where pressing one popped the others out.
Radio buttons with the same name form a , and only one in a group can be chosen. Each has its own value, which is what the server receives, such as size=large.
Each radio button still needs its own id and label. Add checked to one of them when there is a sensible choice to start with.
<form>
<input type="radio" id="small" name="size" value="small">
<label for="small">Small</label>
<input type="radio" id="medium" name="size" value="medium" checked>
<label for="medium">Medium</label>
<input type="radio" id="large" name="size" value="large">
<label for="large">Large</label>
</form> Press show my page to see it here.
Like a checkbox, a radio button has its label after it, so the circle sits on the left.
guess first
Two buttons say checked. Which one is chosen?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<input type="radio" id="tea" name="drink" value="tea" checked>
<label for="tea">Tea</label>
<input type="radio" id="coffee" name="drink" value="coffee" checked>
<label for="coffee">Coffee</label>
your turn
Your turn. Ask how people will pay.
Give both radio buttons the same name, payment, so visitors can pick card or cash but never both.
Press show my page to see it here.
- both buttons are in the payment groupnot checked yet
- no button is left outnot checked yet
fix it
Small and Large are both chosen. Can you fix it?
Press show my page to see it here.
- only one size can be chosennot checked yet
- large is in the size groupnot checked yet
- Two sizes are chosen at once. Are all three buttons in the same group?
- A group is made by the
name. Compare the names on lines 2, 4 and 6. - Change
name="sizes"toname="size"on line 6, then press run.
nailed it
your visitors pick one, and only one. :D
type="radio"makes a round button to pick.- The same
nameputs radio buttons in one group. valueis what the server receives for the choice.
new words in your collection
- radio button
- group
This lesson isn’t saved. A free account remembers every lesson you finish.