html · level 2 · unit 2 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
groups fields, and asks the question.
Radio buttons labelled Yes and No mean nothing on their own. Yes to what? Wrap them in a <fieldset> and the browser draws a box around the group.
The first thing inside a fieldset is its <legend>: the question the group answers. Screen readers say the legend with each choice, such as Need a high chair? Yes.
Use a fieldset for every set of radio buttons or checkboxes, and for any fields that belong together, like the lines of a postal address.
<form>
<fieldset>
<legend>Need a high chair?</legend>
<input type="radio" id="chair-yes" name="chair" value="yes">
<label for="chair-yes">Yes</label>
<input type="radio" id="chair-no" name="chair" value="no">
<label for="chair-no">No</label>
</fieldset>
</form> Press show my page to see it here.
A form can hold several fieldsets, one for each set of questions.
guess first
Where does the legend show up?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<fieldset>
<legend>Pizza toppings</legend>
<input type="checkbox" id="ham" name="ham">
<label for="ham">Ham</label>
<input type="checkbox" id="olives" name="olives">
<label for="olives">Olives</label>
</fieldset>
your turn
Your turn. Ask about the delivery slot.
Wrap the two choices in a <fieldset>, and write a <legend> that asks the question, such as Delivery time.
Press show my page to see it here.
- the fieldset starts with a legendnot checked yet
- both choices sit inside the fieldsetnot checked yet
fix it
The question has slipped out of its box. Can you fix it?
Press show my page to see it here.
- the legend is first in the fieldsetnot checked yet
- there is only one legendnot checked yet
- The question floats above the box instead of sitting on its edge. Where is the
<legend>? - A legend belongs inside its fieldset, as the very first thing.
- Swap lines 2 and 3, so
<legend>comes straight after<fieldset>.
nailed it
your questions come in tidy groups. :D
<fieldset>groups fields that belong together.<legend>comes first and asks the group's question.- Screen readers read the legend with each choice.
new words in your collection
- fieldset
- legend
This lesson isn’t saved. A free account remembers every lesson you finish.