This form uses label association in two ways: with for and id for text and email inputs, and by wrapping the checkbox inside the label. Clicking the labels focuses or toggles the inputs, making the form easier to use and accessible.
A. The input type should be 'username' instead of 'text'
B. The label's for attribute does not match the input's id
C. The label should wrap the input element
D. The input is missing a name attribute
Solution
Step 1: Compare label's for and input's id
Label uses for='username' but input's id='user', so they don't match.
Step 2: Understand association requirement
For label to link input, for and id must be identical.
Final Answer:
The label's for attribute does not match the input's id -> Option B
Quick Check:
for must equal id [OK]
Hint: for and id must be identical to link label and input [OK]
Common Mistakes:
Ignoring mismatch between for and id
Thinking name attribute affects label linking
Assuming wrapping input is always required
5. You want to create a form with two checkboxes labeled 'Subscribe' and 'Accept Terms'. Which code correctly associates each label with its checkbox for best accessibility?
hard
A. <label>Subscribe<input type='checkbox' id='subscribe'></label>
<label>Accept Terms<input type='checkbox' id='terms'></label>
B. <input type='checkbox'><label for='subscribe'>Subscribe</label>
<input type='checkbox'><label for='terms'>Accept Terms</label>
C. <label for='subscribe'>Subscribe</label><input type='checkbox'>
<label for='terms'>Accept Terms</label><input type='checkbox'>
D. <label><input type='checkbox' id='subscribe'>Subscribe</label>
<label for='terms'>Accept Terms</label>
<input type='checkbox'>
Solution
Step 1: Understand two ways to associate labels
Labels can link inputs by wrapping them or using for/id matching.
Step 2: Check each option for correct association
<label>Subscribe<input type='checkbox' id='subscribe'></label>
<label>Accept Terms<input type='checkbox' id='terms'></label> wraps each input inside its label, ensuring correct association without needing for/id.
Final Answer:
<label>Subscribe<input type='checkbox' id='subscribe'></label>
<label>Accept Terms<input type='checkbox' id='terms'></label> -> Option A
Quick Check:
Wrap input inside label or match for/id [OK]
Hint: Wrap input in label or match for and id [OK]
Common Mistakes:
Using for without matching id
Placing label after input without for
Not associating label and input at all
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.