FRM-010 Give every form control a name in code that contains its visible label
- Level
- Rule
- Verdict
- Requirement
- Area
- Forms
- Status
- proposed, version 1.0.1
Rule
Give every form control a name in code that assistive technology can read. When a control has a visible text label, its name contains that text. When a group's options need the group label to make sense, that label can be read in code together with the options.
Examples
Live examples built with Justified's components. Try them with the mouse, the keyboard or a screen reader.
Do: Every control is named by the words beside it
Don't: The words are on screen, the names are not
Why
A screen reader does not look at the screen. It reads the name the control carries in code, and a control with no name is announced as "edit text" or "checkbox" and nothing more. Speech control works the other way round: the person says the word they see, and the control answers only if its name holds that word. And two options that read "Before school" and "After school" say little until the question above them is read too.
Three criteria make this a requirement, one part each. WCAG 2.2, 4.1.2 Name, Role, Value asks that every form control has a name software can work out; a control whose name comes out empty is a documented failure (F68). 2.5.3 Label in Name asks that a control whose label shows text has that text in its name (F96). 1.3.1 Info and Relationships asks that what the layout shows about what belongs together can also be read from the code. For a label and its control, a control whose name is taken from its visible label has met it, and label text on screen beside a control with no name at all does not meet it. For a group, it covers the group label when the options depend on it (see H71 and ARIA17).
None of the three says which technique to use, and none asks that the label can be seen. Whether a control has a visible label is FRM-001.
Do
- On the form Book a swimming course, the label Swimmer's school sits above a text field and is tied to it, for example with
<label for>. The field's name is then "Swimmer's school", the same words as on screen. Tying the label to the control is the way we advise to give the name, because the name can then never drift from the label. The criteria leave the technique open. - The text area Notes for the teacher (optional) is tied to its label the same way.
- Our own advice, since hint text is outside this rule: keep a hint out of the name. Pool card number has the hint "Eight digits, on the back of your card" under it. Tie the hint to the field as a description, for example with
aria-describedby, so the name stays "Pool card number". - A select labelled Pool offers "Northside" and "Harbour". Its name is "Pool" whichever option is chosen.
- A checkbox with the text Tell me when a place becomes free beside it has that text as its name.
- The question When can the swimmer come? has the options Before school and After school. Each radio button is named by its own words, and the question is tied to the group, with a
<fieldset>and<legend>or withrole="radiogroup"andaria-labelledby. A screen reader then reads the question when the person enters the group. - Our own advice, beyond the requirement: tie every visible group label to its group in code. Lesson length over "30 minutes" and "45 minutes" could be understood without it, but tie it anyway, so nobody has to judge each group.
- Swimmer's age is typed in two boxes with the small labels Years and Months. Each box has its own name, and Swimmer's age is tied to the pair as its group label. The group label does not name the boxes.
- A switch above the course list has the label Show full courses. That is its name when it is on and when it is off. On or off is its state, which the switch reports by itself.
- The course list has a search field that shows no label text, only a magnifying glass. The button right beside it shows the word Search, which is the case where FRM-001 lets a field go without label text of its own. The field still has a name in code, such as "Search courses". Our advice is that the name says what the field does. The button is named as ACT-001b says.
- A family booking lists three children, and every row has a select labelled Level. The names are "Level for Alma", "Level for Noor" and "Level for Idris": the visible word is in each, and the rest tells the rows apart. Starting the name with the visible text is our advice, not what 2.5.3 asks.
- The marker in Notes for the teacher (optional) stays in the name. That is what FRM-005 asks. 2.5.3 on its own does not ask for it.
- Our advice: use the native elements where you can. Whether the label text responds to a click or tap is FRM-016a for checkboxes and radio buttons and the guideline FRM-016b for switches.
- In shadcn, give
LabelanhtmlForthat matches the control'sid, or use theFieldcomponent, which does it for you. Put aRadioGroupin theFieldSetcomponent, which gives the group a<legend>, or point it at its visible group label witharia-labelledby.
Don't
- Build a custom select from a
divthat shows "Choose a pool", give itrole="combobox"and no name, so a screen reader says only "combo box". - Put Notes for the teacher (optional) in a paragraph above a text area and leave the two untied, so the words are on screen but the text area has no name.
- Give the select that shows Pool the
aria-label"Venue". Anaria-labelreplaces the label text as the name, so a speech command for the word on screen does nothing. - Write When can the swimmer come? as a plain paragraph over two radio buttons, so a screen reader user hears only "Before school" and "After school".
- Let the switch's name change to "Full courses hidden" when it is turned off while the screen still reads Show full courses.
- Lean on placeholder text to give a field its name. This is our advice, not a reading of 4.1.2: set the name on the control itself.
- Add the role to the name, such as "Pool select". The screen reader already says what kind of control it is. This too is our advice.
Exceptions
- The visible label. This rule is about the name in code. A field named only in code can follow this rule and still break FRM-001, which decides when a label must be seen.
- Text that is not the control's label. 2.5.3 counts the text right next to the control as its label (see Understanding 2.5.3). A heading, a group label or a hint need not be in each control's name. Characters that stand for a function and do not spell a word are not a label either.
- Buttons. Names for buttons, icon-only ones too, are ACT-001b.
- Not covered here. A control's role, state and value, hint text, and error messages are outside this rule. The one thing said about hints under Do, to keep them out of the name, is our advice. Errors follow FRM-002a.
Verdict
Requirement. Only the judges decide; the expert witnesses are shown but do not vote. How verdicts work
| Source | Role | Stance | Page |
|---|---|---|---|
| WCAG 2.2 | Law | Requires | 4.1.2 Name, Role, Value |
| WCAG 2.2 | Law | Requires | 2.5.3 Label in Name |
| WCAG 2.2 | Law | Requires | 1.3.1 Info and Relationships |
| Material Design | Judge | Supports | Text fields: accessibility Checkbox: accessibility Radio button: accessibility Switch: accessibility Search: accessibility Accessibility designing: elements |
| Apple Human Interface Guidelines | Judge | No position | |
| Carbon Design System | Judge | Supports | Text input: accessibility Form: accessibility Checkbox: accessibility Radio button: accessibility Search: accessibility |
| GOV.UK Design System | Expert witness | No position | |
| Nielsen Norman Group | Expert witness | No position |
Each stance links to the page it rests on, read on the date in the source register. This page never repeats what a source says; read the source itself.
History
- Version 1.0.1, : Refers to FRM-016a and FRM-016b for label text that responds to a click or tap.
- Version 1.0.0, : First version. Takes over the name in code from FRM-001, which now covers the visible label only.
Last checked against the other rules for conflicts on .
More in Forms: 15 rules and 12 guidelines · All rules
Justified is an independent project. It is not affiliated with, sponsored or endorsed by the organisations whose guidance it cites. Read the full statement.
Apple is a trademark of Apple Inc., registered in the U.S. and other countries and regions.