Pass the menu and read the page

SignupFolio

Signup form names: 5 ways to label controls clearly

Name signup form controls with connected labels, native button text or ARIA, and check that each accessible name includes its visible label.

Key takeaways

  • Start with native HTML labels and button text.
  • Use aria-labelledby to connect existing visible text when a label element cannot be used.
  • Reserve aria-label for controls that need another naming method.
  • Check names in the accessibility tree and listen with a screen reader.

A signup form asks for only a few things: an email address, a password, perhaps a name, a checkbox for the terms, and a button to submit. A sighted person reads the visible text and understands each one at a glance. A screen reader user hears the control's accessible name instead. If that name is missing, vague, or contradicts what is on the screen, the person may not know what to type or which button will create their account.

This post covers five ways to give each control a proper accessible name. Two are native HTML methods, two use ARIA attributes, and the last is a check that keeps the name in step with the visible text. The examples use a typical signup page. The ideas apply to any form builder or framework, because the browser computes names from the markup it receives, whatever tool produced that markup.

If you build or review signup forms without writing the markup yourself, the code here is still worth reading. You will learn to recognize the patterns, ask your developers the right questions, and spot a missing name quickly. The review pass near the end of this post is written with that job in mind.

Why the accessible name matters

Screen reader users often move from one form field to the next, and at each stop the software announces the control's role, its name, and its state. The name is the part that answers the question "what is this for?" Browsers build it from several sources. The W3C's guidance on Label in Name points to the Accessible Name and Description Computation and the HTML Accessibility API Mappings, which describe how the name is computed, including which attributes are considered and in what order of preference (W3C).

You do not need to memorize that order to build a good form. You do need to know one thing that trips up many teams: text that looks like a label is not always the name. The same W3C page notes that other text displayed on the screen is not normally factored into the calculation for the accessible name of a UI component without author intervention, such as ARIA labeling techniques. A heading placed above a field, or a hint printed under a button, does nothing for the name until you connect it in code.

The stakes are set out in the same guidance. When a component lacks an accessible name and has a visible text label, it fails 4.1.2 Name, Role, Value, and it also fails 2.5.3 Label in Name. A missing name is therefore both a usability problem and a conformance problem. A review of a signup form should catch it either way, and it is usually cheap to fix once you know where to look.

Ways 1 and 2: start with native HTML

Native HTML provides naming methods for most form controls, so use it first. Native markup is shorter, works without scripts, and needs no extra attributes that someone has to keep in sync when the page changes.

Way 1: use a label element. WebAIM describes the label element as the element that programmatically associates a text label to a form control, creating a connection in the code that does not rely on vision (WebAIM). You link the label to the input with a matching for and id pair, or you wrap the input inside the label element.

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

MDN states the default rule directly: a form input's accessible name is the content of the associated label element (MDN).

Keep the label visible. Example text inside a field can hint at the expected format, but it disappears as soon as someone starts typing, so it cannot stand in for a label. Place the label in the usual position, above or before the control. The W3C page explains that the rationale for some of its label conventions is given in G162, "Positioning labels to maximize predictability of relationships" (W3C). In other words, a label in a familiar spot helps everyone predict which label belongs to which control, including people who cannot see the layout.

When several controls answer one question, such as a set of radio buttons for a plan choice, wrap them in a fieldset with a legend instead of a bare group of inputs. The legend gives the group its name in the same way the heading does in Way 3, and the native markup does the job without any ARIA attributes. The same logic applies to select menus and textareas: give each one a visible label connected in code, and the name follows.

Way 2: let the default name of a button or image do the work. MDN describes the defaults: a button's accessible name is the content between its opening and closing button tags, and an image's accessible name is the content of its alt attribute (MDN). For a submit button, the words inside the tags are the name.

<button type="submit">Create my account</button>

The name here is "Create my account", and no attribute is needed. Choose wording that says what happens when the button is used. "Submit" tells a screen reader user very little, and "Continue" is vague on a page that takes payment details. If a button contains an image, write alt text that describes the action rather than the picture.

The same care applies to links. A link that reads "Terms of service" tells a screen reader user where it leads. A link that says only "Read more" or "Click here" gives the name almost no detail. When the visible words are vague, change the words on the page first. That helps every reader, and it is a better fix than hiding a clearer name in an attribute.

Ways 3 and 4: ARIA when native markup is not enough

Sometimes the visible text is not inside a label element. A group of plan choices may sit under a heading, or a custom widget may draw its own text on the page. WebAIM notes that ARIA labels, aria-labelledby and aria-label, may be used when it is not possible to use a label element (WebAIM). Treat the ARIA options as a second choice, not the first.

Way 3: point to visible text with aria-labelledby. This attribute takes the id of another element on the page and uses that element's text as the name. MDN is clear about the order of preference: it is strongly recommended to prioritize the use of aria-labelledby over aria-label if a visible label exists for the element to reference and receive its name from (MDN).

<h2 id="plan-heading">Choose a plan</h2>
<div role="radiogroup" aria-labelledby="plan-heading">
  <!-- plan options go here -->
</div>

The radio group now takes the name "Choose a plan" from the heading that sighted users already see. If the heading text changes, the name changes with it, so the name never drifts from what is on the screen. Make sure the id is unique on the page. A duplicate id can point the name at the wrong element, and the control may then announce a heading that has nothing to do with it.

Way 4: use aria-label when nothing visible is available. MDN gives the sequence to follow. If none of the other options are available, or if the default accessible name is not appropriate, use the aria-label attribute to define the accessible name of an element (MDN). The most common case on a signup form is an icon-only button, such as an eye icon that shows or hides the password.

<button type="button" aria-label="Show password">
  <svg aria-hidden="true" focusable="false"><!-- eye icon --></svg>
</button>

Write the aria-label as a short, plain description of what the control does. Do not repeat the word "button" in it, because the screen reader already announces the role. Do not pack several instructions into one label either. The name should be enough to tell the user what happens next, and nothing more.

Hints and error messages need their own home. Password rules, format notes, and error text are useful, but they do not belong inside the name. Connect them with a description attribute such as aria-describedby, so the name stays short and the hint is still announced with the control. A name that carries the whole explanation is hard to scan, and it is also harder to keep accurate when the rules change.

For related markup checks, see signup accessibility mistakes.

Compare the five ways side by side

The table compares the five ways so you can pick the right one for each control. The last column gives the check to run after you apply it.

WayBest forNeeds visible text?Check after you apply it
1. Label elementText inputs, selects, textareas, checkboxesYes, a visible labelThe label is connected to the control in code
2. Default nameButtons with text, images with alt textButton text is visible; alt text names an imageThe name says what the control does
3. aria-labelledbyGroups, custom widgets, labels in other elementsYes, a visible element on the pageThe referenced id exists once on the page
4. aria-labelIcon-only buttons and controls with no visible textNoThe label describes the purpose in plain words
5. Name includes visible textAny control that shows a visible labelYesThe accessible name contains the visible words

Read the table as a decision list. Start at the top. If a native option fits the control, use it, and move down the list only when it does not. Most signup forms need the first two ways for almost every control, and reach for the ARIA options only for the handful of widgets that have no native equivalent.

Way 5: keep the name in step with visible text

The fifth way is less a new technique than a rule that applies to the other four. When a control shows visible text, its accessible name should include that text. The Label in Name criterion, 2.5.3, is about this match between what is shown and what the name says (W3C). The idea behind the criterion is that the words a sighted person reads should also be the words the name offers, so the control means the same thing to everyone who uses it.

Mismatches usually creep in over time rather than on day one. A designer changes the button text from "Join" to "Sign up", a developer adds an aria-label months earlier, and nobody notices that the two no longer agree. This is one reason the check belongs in every review, not only the first one.

The easiest way to break this rule is with aria-label. Suppose a button shows the visible text "Sign up", but its aria-label reads "Create account". A sighted user sees one thing, and the name says another. Someone who says "click sign up" may get no response, because the words they spoke are not in the name.

<button type="submit" aria-label="Sign up for free">Sign up</button>

Here the name starts with the words the user sees. Even simpler, you can remove the aria-label and let the default button text serve as the name.

For a focused review, use the guide to visible labels and accessible names.

A review pass for your signup form

Run these checks on every control before launch, and again after anyone edits the form.

  • Every input has a visible label, connected with a matching for and id pair, or wrapped inside the label element.
  • Every button and link has a name that says what happens when it is used.
  • Every icon-only control has an accessible name that describes its purpose in plain words.
  • No aria-label contradicts or leaves out the visible text on its control.
  • Every aria-labelledby points to an id that exists exactly once on the page.
  • No field relies only on example text inside it for its label.
  • The name of each control appears in the browser's accessibility tree, which most developer tools can show.
  • You can tab through the whole form with the keyboard, and a screen reader announces a clear name at every stop.

Checking the names by hand takes little time. Open the form in a browser and use the developer tools to inspect the accessibility tree, where each control shows its role and its name. Then move through the form with the Tab key, turn on a screen reader such as VoiceOver, NVDA, or TalkBack, and listen to what each control announces. If the announcement and the visible label disagree, fix the markup before you sign off on the form.

Illustrative example: connect labels to controls

Suppose a signup form pairs a full name field with a terms checkbox. Connect each label to its input, then inspect the names.

<label for="signup-name">Full name</label>
<input id="signup-name" type="text" autocomplete="name">

<input id="signup-terms" type="checkbox">
<label for="signup-terms">I agree to the terms of service</label>

Both controls have a visible label that is connected in code, so both have a name. The checkbox's name is its own label text, not a sentence from elsewhere on the page. Neither field needs an aria-label, and the native markup does the work.

Your next step today

Open your signup form and inspect the first input's accessible name. If it has no name, connect its visible label in code and check it again.

Questions and answers

What names a standard form input?

The associated label element supplies a form input's default accessible name. Match its for value to the input's id, or wrap the input inside the label element.

When should I use aria-label?

Use aria-label when other naming options are unavailable or the default name is inappropriate. An icon-only password button is an example; its name should describe the action.

How do I check the result?

Inspect the control's name in the browser's accessibility tree, then listen with a screen reader. Compare what it announces with the visible label before signing off on the form.

Sources and check date

Related posts

More posts