Should form labels be wrapped or separate?

Is it strictly necessary for form fields and labels to have for/id association, or is it enough to wrap the label around the input?

The post Should form labels be wrapped or separate? appeared first on TPGi.


This content originally appeared on TPGi and was authored by James Edwards

Several times this year, I’ve answered variations of the following question:

Is it strictly necessary for form fields and labels to have for/id association, or is it enough to wrap the <label> around the <input>

The answer is — Wrapping is enough in theory, but isn’t quite in practice.

What’s the difference?

All form fields must have an associated label, so that screen reader users know which field the label is referring to, and so that voice control users can speak the label text to focus the field (e.g., Click email address for a field labeled “Email address”). The association also provides a pointer shortcut, making it possible to focus the field by clicking the label.

Wrapping the label around the field is known as implicit association, and it’s a very common pattern:

<label>
    Email address
    <input type="email">
</label>

This pattern is often cited as a usability benefit, since it makes the whole area clickable, rather than the label and field being separate targets, which can be particularly helpful if they’re not directly next to each other.

However if the label and field are separate elements, then they must be associated using for and id attributes, which is known as explicit association:

<label for="email">Email address</label>
<input id="email" type="email">

So what’s the problem?

All browsers and assistive technologies support explicit association, however implicit association is not reliably supported by voice control software.

Both Dragon Naturally Speaking for Windows, and Voice Control for macOS and iOS, don’t recognize implicit association, so the Click email address command wouldn’t work.

This is not a blocker, because users have multiple ways to reach and activate controls. For example, Voice Control users can say Show numbers to show an overlay of numbers next to every interactive element, and then say the relevant number to use that control.

But the problem is easily fixable anyway, simply by adding explicit association:

<label for="email">
    Email address
    <input id="email" type="email">
</label>

Conclusion

Wrapping the <label> around the <input> is fine, and is sufficient for conformance on its own, however adding explicit association with for and id is still necessary in practice.

Resources


Image credit: Alpha.

The post Should form labels be wrapped or separate? appeared first on TPGi.


This content originally appeared on TPGi and was authored by James Edwards


Print Share Comment Cite Upload Translate Updates
APA

James Edwards | Sciencx (2024-09-04T15:16:20+00:00) Should form labels be wrapped or separate?. Retrieved from https://www.scien.cx/2024/09/04/should-form-labels-be-wrapped-or-separate/

MLA
" » Should form labels be wrapped or separate?." James Edwards | Sciencx - Wednesday September 4, 2024, https://www.scien.cx/2024/09/04/should-form-labels-be-wrapped-or-separate/
HARVARD
James Edwards | Sciencx Wednesday September 4, 2024 » Should form labels be wrapped or separate?., viewed ,<https://www.scien.cx/2024/09/04/should-form-labels-be-wrapped-or-separate/>
VANCOUVER
James Edwards | Sciencx - » Should form labels be wrapped or separate?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/04/should-form-labels-be-wrapped-or-separate/
CHICAGO
" » Should form labels be wrapped or separate?." James Edwards | Sciencx - Accessed . https://www.scien.cx/2024/09/04/should-form-labels-be-wrapped-or-separate/
IEEE
" » Should form labels be wrapped or separate?." James Edwards | Sciencx [Online]. Available: https://www.scien.cx/2024/09/04/should-form-labels-be-wrapped-or-separate/. [Accessed: ]
rf:citation
» Should form labels be wrapped or separate? | James Edwards | Sciencx | https://www.scien.cx/2024/09/04/should-form-labels-be-wrapped-or-separate/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.