Labels (label and for), online
Six activities your students do on their own devices. See who's finished, and their scores.
Labels (label and for) in one minute
What students need to know
Both for and id hold the value 'email'. If they differ - even in case - the label and input are not linked. The label describes the purpose of the password field. Screen readers announce 'Password' when the input receives focus.
The for attribute holds the id of the target input. 'name' is an attribute on inputs, not labels. HTML tag names must be lowercase. <LABEL> is non-standard - use <label>.
Mistakes students make
- HTML tag names must be lowercase. <LABEL> and </LABEL> should be <label> and </label>.
- Attribute names must be lowercase. 'For' should be written as 'for': for="email".
- The input is missing the id attribute that matches the label's for value. Add id="user" to link them.
- Attribute names must be lowercase. 'For' should be written as 'for': for="pass".
What students will learn in this module
Every question in Module 29
Quick questions
- Which attribute on <label> links it to an input?AnameBfor
- True or false: the for value and the input id must match exactly (case-sensitive).ATrueBFalse
- What happens when a user clicks a label linked to an input?AFocus moves to the associated inputBThe form is submitted
- True or false: <LABEL> with capital letters is valid HTML.ATrueBFalse
- Why is linking labels to inputs important for accessibility?AScreen readers announce the label text when the input is focusedBIt adds colour to the input field
Key terms
Students type the meaning of:
for
Match the pairs
<label for="name">Full name</label> <input type="text" id="name">Match it to what it does
<label for="agree">I agree</label> <input type="checkbox" id="agree">Match it to what it does
The for attribute value must exactly match the input's id - the match is case-sensitiveMatch it to what it doesEvery visible form control should have an associated <label> for accessibilityMatch it to what it does<label For="city">City</label> <input type="text" id="city">Match it to what it does
<label for="age">Age</label> <input type="number" id="AGE">Match it to what it does
Fill in the blanks
<_____ for="name">Your name</label>
Hint: Type the element name used to provide a visible text label for a form control
<label for="email">Email</_____>
Hint: Type the element name for the closing tag of a label
<label for="user">User</label> <input type="text" __="user">
Hint: Type the attribute name on the input that must match the label's for value
<label for="____">Password</label> <input type="password" id="pass">
Hint: Type the id value that this label's for attribute must match exactly
<_____ for="city">City</label> <input type="text" id="city">
Hint: Type the element name that wraps visible label text for a form control
Spot the error
Question 1
A<LABEL for="name">Name</LABEL>B<input type="text" id="name">C<button>Submit</button>
Question 2
A<form>B <label For="email">Email</label>C <input type="email" id="email">D</form>
Question 3
A<form>B <label for="user">Username</label>C <input type="text">D <button>Login</button>E</form>
Question 4
A<form>B <label For="pass">Password</label>C <input type="password" id="pass">D</form>
Question 5
A<form>B <label for="a">First</label>C <input type="text" id="a">D <label for="b">Last</label>E <input type="text" id=b>F</form>
