edubun
English
1 / 18

5 / 6 · Intermediate

Form labels

A text box next to the word "Email" is not labelled until the label element is tied to it; until then a screen reader may say only "edit text".

Jump to the 10 practice questions

You will learn

  • Tie every field to a label
  • Group choices with fieldset and legend
  • Give instructions and errors in words

Before this: Using a page with the keyboard

1Explore

What a field announces

When focus lands on a form field, a screen reader announces its label, its type and its state: "Email, edit text, required". The label comes from a label element tied to the field. There are two ways to tie them. Give the input an id and the label a matching for, or put the input inside the label. Either way, clicking the label text also moves focus into the field, which makes small checkboxes and radio buttons much easier to hit.

The email field is named by its label; the phone field has only a paragraph above it, so it is announced with no name.

Your code
<form>
  <label for="email">Email</label>
  <input id="email" type="email" required>
  <p>Phone</p>
  <input id="phone" type="tel">
  <label><input type="checkbox"> Send me the weekly menu</label>
</form>
Preview
What a screen reader announces (simplified)

    2Problem

    label and id

    Which attribute on label points to the id of its input?

    Hint

    The attribute on label that names the input id.

    Solution

    Answer: for

    for on the label matches id on the input.

    3Problem

    Clicking the label

    What else happens when a label is tied to a checkbox?

    Hint

    Click "Send me the weekly menu" in the preview.

    Solution

    Answer: Clicking the label text ticks the box

    The label becomes part of the click target.

    4Problem

    A correctly labelled field

    Which is a correctly labelled field?

    Hint

    for and id must match.

    Solution

    Answer:

    for and id match. The last one has a label with no for and the input is outside it.

    5Explore

    Placeholder is not a label

    The placeholder attribute shows grey hint text inside an empty field. It is tempting to use it instead of a label, and many sign-up forms do. The trouble is that it disappears as soon as you type, so you cannot check what the field was for, and it is usually pale enough to fail the contrast rules from the previous unit. Use a visible label and, if you like, a placeholder with an example value as well.

    The first field has only a placeholder: no name. The second keeps the hint and has a real label.

    Your code
    <input type="email" placeholder="you@example.com">
    <label for="mail">Email</label>
    <input id="mail" type="email" placeholder="you@example.com">
    Preview
    What a screen reader announces (simplified)

      6Problem

      Why a placeholder is not enough

      Why is a placeholder not enough as a label?

      Hint

      What happens when you start typing?

      Solution

      Answer: It disappears when you type and is often too pale

      The hint vanishes and usually fails contrast.

      7Explore

      Groups and autocomplete

      Radio buttons and related checkboxes need a group label too. Wrap them in a fieldset and put the question in its legend, so a screen reader says "Size, group" before "Small, radio button, 1 of 3". For personal details, the autocomplete attribute tells the browser what a field is for, using names from the HTML standard such as name, email, tel, new-password and one-time-code. Criterion 1.3.5 Identify Input Purpose, at level AA, asks for exactly this, because it lets browsers fill fields in and lets some tools show familiar icons next to them.

      The legend becomes the name of the group, announced before each choice.

      Your code
      <fieldset>
        <legend>Size</legend>
        <label><input type="radio" name="size"> Small</label>
        <label><input type="radio" name="size"> Medium</label>
        <label><input type="radio" name="size"> Large</label>
      </fieldset>
      Preview
      What a screen reader announces (simplified)

        8Problem

        A question for radio buttons

        Which elements give a group of radio buttons its question?

        Hint

        Look at the group line above.

        Solution

        Answer: fieldset and legend

        The legend is announced as the group name.

        9Problem

        autocomplete for email

        Which autocomplete value should an email field use?

        Hint

        The value is the same word as the type.

        Solution

        Answer: email

        Use autocomplete="email" so the browser recognises an email address field. The visible label identifies it to the person; the autocomplete value identifies its purpose to software.

        10Problem

        Identify input purpose

        Which criterion asks fields for personal data to identify their purpose?

        Hint

        Criterion 1.3.5.

        Solution

        Answer: 1.3.5 Identify Input Purpose

        Criterion 1.3.5, level AA, makes the purpose of personal-data fields available to software. Standard autocomplete values let browsers offer the right stored information.

        11Explain

        Errors in words

        When something goes wrong, say so in words. Criterion 3.3.1 Error Identification asks that an input error is identified and described to the user in text, not only by turning the border red. WCAG 2.2 also added 3.3.7 Redundant Entry: information a person already entered in the same process should be filled in again for them or offered to select, instead of being typed twice. And 3.3.8 Accessible Authentication (Minimum), at level AA, says a login step must not depend on remembering or transcribing something unless help is available.

        12Problem

        A red border only

        An error is shown only by a red border. What is missing?

        Hint

        Colour alone is not enough.

        Solution

        Answer: A text description of the error

        3.3.1 asks for errors to be described in text, and 1.4.1 forbids colour as the only cue.

        13Problem

        The address again

        A checkout asks for the delivery address again on the next step. Which criterion helps?

        Hint

        A WCAG 2.2 criterion about entering things twice.

        Solution

        Answer: 3.3.7 Redundant Entry

        Criterion 3.3.7 avoids entering the same information again in one process. Reuse the earlier address or offer it for selection rather than making the person retype it.

        14Problem

        Blocking paste

        A login form blocks paste in the password field. Which WCAG 2.2 criterion does that work against?

        Hint

        A criterion about logging in.

        Solution

        Answer: 3.3.8 Accessible Authentication (Minimum)

        Criterion 3.3.8 supports help with authentication instead of requiring unaided recall or transcription. Allowing paste and password-manager filling provides that help; blocking paste removes one route.

        15Practice

        Labels and autocomplete

        The two fields are labelled only by paragraphs. Replace each paragraph with a label tied to its input with for, and add autocomplete="name" and autocomplete="email".

        Checks
        • label for name
        • label for email
        • autocomplete="name"
        • autocomplete="email"
        Your code
        <form>
          <p>Name</p>
          <input id="name" type="text">
          <p>Email</p>
          <input id="email" type="email" placeholder="you@example.com">
          <button>Send</button>
        </form>
        Preview
        Hint

        Two labels with for, and an autocomplete on each input.

        A solution
        <form>
          <label for="name">Name</label>
          <input id="name" type="text" autocomplete="name">
          <label for="email">Email</label>
          <input id="email" type="email" autocomplete="email" placeholder="you@example.com">
          <button>Send</button>
        </form>

        16Practice

        A fieldset with a legend

        Group the three size buttons in a fieldset and turn the "Size" paragraph into its legend.

        Checks
        • legend inside fieldset
        • three radios inside
        Your code
        <form>
          <p>Size</p>
          <label><input type="radio" name="size" value="s"> Small</label>
          <label><input type="radio" name="size" value="m"> Medium</label>
          <label><input type="radio" name="size" value="l"> Large</label>
        </form>
        Preview
        Hint

        legend goes inside fieldset, and the radio buttons too.

        A solution
        <form>
          <fieldset>
        <legend>Size</legend>
          <label><input type="radio" name="size" value="s"> Small</label>
          <label><input type="radio" name="size" value="m"> Medium</label>
          <label><input type="radio" name="size" value="l"> Large</label>
        </fieldset>
        </form>

        17Explain

        Common mistakes

        Mistake
        <style>
          .err { border: 2px solid #c01c28; }
        </style>
        <label for="pc">Postcode</label>
        <input id="pc" class="err" value="AB1">
        Fixed
        <style>
          .err { border: 2px solid #c01c28; }
        </style>
        <label for="pc">Postcode</label>
        <input id="pc" class="err" value="AB1" aria-describedby="pc-err">
        <p id="pc-err">Error: a postcode has 5 or more characters.</p>

        A red border alone does not say what is wrong. Describe the error in text next to the field.

        18

        Summary

        • Tie each field to a label with for and id, or by wrapping.
        • A placeholder disappears and is often too pale; it is not a label.
        • Group radios with fieldset and legend; use autocomplete for personal data.
        • Describe errors in text; do not make people retype or memorise to log in.

        Next unitScreen readers and the first rule of ARIA
        Full text · The whole lesson as one text

        Every field needs a name

        When focus lands on a form field, a screen reader announces its label, its type and its state: "Email, edit text, required". The label comes from a label element tied to the field. There are two ways to tie them. Give the input an id and the label a matching for, or put the input inside the label. Either way, clicking the label text also moves focus into the field, which makes small checkboxes and radio buttons much easier to hit.

        <label for="email">Email</label>
        <input id="email" type="email" autocomplete="email">
        
        <label>
          <input type="checkbox" name="news"> Send me the weekly menu
        </label>
        Two ways to label a field: for and id, or wrapping.

        WCAG 2.2 success criterion 3.3.2 Labels or Instructions, at level A, asks for labels or instructions whenever content needs user input. And 1.3.1 Info and Relationships asks that the link between label and field exists in the code, not only on screen. A paragraph that happens to sit above an input is only visually close; nothing tells assistive technology that the two belong together.

        Placeholders are not labels

        The placeholder attribute shows grey hint text inside an empty field. It is tempting to use it instead of a label, and many sign-up forms do. The trouble is that it disappears as soon as you type, so you cannot check what the field was for, and it is usually pale enough to fail the contrast rules from the previous unit. Use a visible label and, if you like, a placeholder with an example value as well.

        Groups, purpose and errors

        Radio buttons and related checkboxes need a group label too. Wrap them in a fieldset and put the question in its legend, so a screen reader says "Size, group" before "Small, radio button, 1 of 3". For personal details, the autocomplete attribute tells the browser what a field is for, using names from the HTML standard such as name, email, tel, new-password and one-time-code. Criterion 1.3.5 Identify Input Purpose, at level AA, asks for exactly this, because it lets browsers fill fields in and lets some tools show familiar icons next to them.

        When something goes wrong, say so in words. Criterion 3.3.1 Error Identification asks that an input error is identified and described to the user in text, not only by turning the border red. WCAG 2.2 also added 3.3.7 Redundant Entry: information a person already entered in the same process should be filled in again for them or offered to select, instead of being typed twice. And 3.3.8 Accessible Authentication (Minimum), at level AA, says a login step must not depend on remembering or transcribing something unless help is available. Letting password managers fill the field and allowing paste both count as that help.

        Say what is needed before people start

        Instructions belong before the fields they describe, not in an error message after someone has failed. If a password must be at least 15 characters, say so next to the label. Mark required fields in the label text, for example with the word "required", and add the required attribute so the browser also announces it. When an error message appears, keep it next to its field and tie the two together with aria-describedby pointing at the message's id. The screen reader then reads the message when the field gets focus. Finally, move focus to the first field with a problem, or to a summary of the errors at the top. Then a keyboard user is not left at the bottom of a long form wondering what happened.

        Key points
        • Tie each field to a label with for and id, or by wrapping.
        • A placeholder disappears and is often too pale; it is not a label.
        • Group radios with fieldset and legend; use autocomplete for personal data.
        • Describe errors in text; do not make people retype or memorise to log in.

        Practice questions from Form labels on edubun

        Embed this quiz

        Free to embed. Please keep the credit line.

        Sources for this course (8)
        • W3C, Web Content Accessibility Guidelines (WCAG) 2.2, W3C Recommendation first published 5 October 2023, current edition 12 December 2024 (w3.org/TR/WCAG22/, checked 2026-10-17)
        • W3C WAI, What's new in WCAG 2.2 (w3.org/WAI/standards-guidelines/wcag/new-in-22/, checked 2026-10-17)
        • W3C WAI, Images tutorial and alt decision tree (w3.org/WAI/tutorials/images/decision-tree/, checked 2026-10-17)
        • W3C, Using ARIA (w3.org/TR/using-aria/, Discontinued Draft 24 February 2026, rules 1 to 4, checked 2026-10-17)
        • W3C WAI-ARIA Authoring Practices Guide, Read Me First, "No ARIA is better than bad ARIA" (w3.org/WAI/ARIA/apg/practices/read-me-first/, checked 2026-10-17)
        • MDN Web Docs, tabindex (developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/tabindex, checked 2026-10-17)
        • MDN, Heading elements, accessibility notes (developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/Heading_Elements, checked 2026-10-17)
        • MDN, autocomplete attribute (developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/autocomplete, checked 2026-10-17).

        Checked: 2026-10-17