Skip to content

    Frontend System Design

    Accessible Forms and Dynamic Content

    Build forms and live updates that assistive technology can follow: labels, hints, errors, where focus goes after a failed submit, and polite status messages.

    By Published 13 min read

    • frontend-system-design
    • accessibility
    • forms
    • live-regions
    • aria
    Share

    Standard lessonintermediateReact labFrontend System Design

    Before this: Semantic HTML, ARIA and Accessible Names, Form State and Validation

    What you'll learn: By the end of this lesson you will be able to give every form control a programmatic name, hint and error, write error messages that say what is wrong and how to fix it, decide where focus goes after a failed submit, choose between moving focus, a polite status message and an alert for a change that happens without a page load, and say what a jsdom test can and cannot show about a screen reader.

    Think of filling in a form at a counter. A good clerk tells you what each box is for, points to the exact box when something is wrong and says "saved" when you finish. A bad clerk hands you unnamed boxes, says "there was a problem" and walks off. For a screen-reader user the page is the clerk: it alone can say what a box is, which one is wrong and that something happened.

    The running example is the delivery details form and the product search of the ShopStream grocery marketplace: a form with a name, an email, an optional phone number and an optional note, and a search that filters a list as the shopper types.

    The core idea

    1. Every control needs a name, and its extra text must be attached to it. The name comes from a label. Hints and errors are not part of the name, but they are linked so they are read with the control.
    2. An error is three jobs: identify the field, describe the problem in text, and, when you can, say how to fix it. Then decide where focus goes.
    3. A change with no page load tells a screen-reader user nothing by itself. You have two tools: move focus (the user must act on this) or write into a live region (the user should know, but need not act).

    Figure 1. What each field is wired to

    One field: label, hint and error all attached to the inputLabel to Input (name); Hint to Input (description); Error text to Input (description); Input to A11y treeLabel: for / idLabelfor / idHint: aria-describedbyHintaria-describedbyError text: only when invalidError textonly when invalidInput: invalid, requiredInputinvalid, requiredA11y tree: name, descriptionA11y treename, descriptionnamedescriptiondescription

    How to read this: three separate pieces of text point at one input. The label supplies its name; the hint and the error supply its description. The warning box exists only after validation has found a problem.

    Labels, hints and the description

    A label with a for attribute equal to the control's id associates the two. MDN recommends this explicit association for compatibility with assistive technologies (nesting also works). Clicking the label passes focus to the control. MDN warns against putting extra interactive content or headings inside a label. WCAG 3.3.2 (Labels or Instructions, level A) requires labels or instructions when content requires user input.

    A hint ("We send your receipt here.") is not the name. aria-describedby takes one or more element ids and supplies the control's description: more information the user might need, where a label describes the essence of the object and should be concise. MDN notes the referenced elements need not be visible and should hold text; for structured content aria-details fits better.

    The autocomplete attribute takes defined tokens such as name, email and tel. MDN says valid tokens also satisfy WCAG 1.3.5 (Identify Input Purpose, level AA), and that autocomplete="off" and invented tokens undermine it.

    Illustration 1: the minimal example

    The lab builds each field's attributes from a small spec and prints them. Before any submit, the email field is described by its hint, is required, and is not marked invalid:

    Expected output, captured from a real run (Node 26.13.1, 2026-12-01; section 1 of the demo):

    === 1. Attributes before the first submit
      name
        aria-describedby   (absent)
        aria-invalid       (absent)
        required           true
        autocomplete       name
      email
        aria-describedby   email-hint
        aria-invalid       (absent)
        required           true
        autocomplete       email
      phone
        aria-describedby   phone-hint
        aria-invalid       (absent)
        required           false
        autocomplete       tel
      note
        aria-describedby   note-hint
        aria-invalid       (absent)
        required           false
        autocomplete       (absent)

    aria-invalid is absent everywhere, on purpose: MDN says to set it from script as a result of validation, and not to set it on empty required fields before the user has tried to submit, because they may still be filling the form in.

    In jsdom, Testing Library computes an accessible name and description for each element and jest-dom asserts them, such as toHaveAccessibleDescription("We send your receipt here."). For contrast, the lab includes a field built the common wrong way: a span that is not a label, an unassociated input and an error paragraph that points at nothing. Its test shows an empty accessible name and description. It looks the same on screen as the good one.

    Errors: identify, describe, suggest

    WCAG 3.3.1 (Error Identification, level A): when an input error is automatically detected, the item in error is identified and the error is described to the user in text. WCAG 3.3.3 (Error Suggestion, level AA): when suggestions for correction are known, they are provided, unless that would jeopardize the security or purpose of the content. The WAI forms tutorial adds that feedback at or near the control helps most, that a field can be associated with its error through aria-describedby, and it pairs red styling with a text "Error:" label rather than relying on colour alone.

    The lab's messages name the field and the fix: "Enter your full name", "Enter an email address in the format name@example.com". The error paragraph starts with the visible word "Error:" and its id comes after the hint id in aria-describedby, so the description reads "hint, then error".

    aria-invalid="true" marks the control as failing validation; MDN says to set it with script after validation, together with a message the user can find. aria-errormessage points at the element holding the message and relies on aria-invalid; this lesson uses aria-describedby for the error, as the WAI tutorial does, and claims nothing about how well aria-errormessage is supported by any screen reader. Test it with your users' tools if you use it.

    After a failed submit: where does focus go?

    With no page load, a failed submit changes nothing for a screen-reader user unless you act. The WAI forms tutorial suggests listing the errors at the top of the form (the container may have role="alert" when errors appear dynamically) and setting focus to the first input in error. Each has a cost.

    • Focus the first invalid field. The user lands where they can fix something, but hears only that field, not that there are three problems.
    • Focus an error summary (a heading and links to the fields). The user hears the count and the list, and each link moves focus to its field. The summary needs tabindex="-1" so script can focus it without adding a tab stop. The cost is one more step.

    Figure 2. A failed submit, with a summary

    sequenceDiagram accTitle: A failed submit with an error summary accDescr: The shopper presses Save with the name empty and a malformed email. The form validates, sets aria-invalid on the two fields, renders an error summary listing both problems, and moves focus to the summary. The shopper follows the link for the email, focus moves to that field, its description is read, the shopper fixes it and submits again. A status region, already in the page, then says the details were saved. participant U as Shopper participant F as Form participant S as Summary participant R as Status region U->>F: presses Save (name empty, email malformed) F->>F: validate, set aria-invalid and error text F->>S: render list of 2 problems F->>S: focus() the summary U->>S: follows the link for the email S->>F: focus() the email field U->>F: corrects it, presses Save F->>R: write "Delivery details saved"

    How to read this: focus moves twice (to the summary, then to a field) and both moves are the user's task to continue. The final message goes to a region that was already there, and focus does not move at all.

    Illustration 2: the realistic example

    For a submit with the name empty and the email malformed, the pure model builds the summary and picks the focus target for each strategy:

    Expected output, captured from a real run (Node 26.13.1, 2026-12-01; section 2 of the demo):

    === 2. A submit with the name empty and a malformed email
      summary heading: There are 2 problems with your details
      - #name: Enter your full name
      - #email: Enter an email address in the format name@example.com
      focus (strategy first-field): name
      focus (strategy summary):     error-summary
      name
        aria-describedby   name-error
        aria-invalid       true
      email
        aria-describedby   email-hint email-error
        aria-invalid       true

    The summary lists problems in the order the fields appear, and the email now has a two-id description (hint, then error). In React, focus moves in an effect after the render that shows the errors, because the summary does not exist until then. The tests check document.activeElement for both strategies and that a summary link moves focus to its field. The form uses noValidate so the browser's own bubbles do not compete with these messages; that is this lab's choice, not a rule.

    Dynamic content and live regions

    When content changes without a page load, such as a result count updating while the shopper types, a screen reader has no navigation event to react to. A live region is the tool. MDN describes aria-live with three values: off (the default), polite (presented at the next graceful opportunity) and assertive (presented immediately, possibly clearing the speech queue). Two roles package this: role="status" has an implicit aria-live of polite and aria-atomic of true and must not be given focus; role="alert" is equivalent to assertive and atomic, and MDN says to use it sparingly because alerts are disruptive. WCAG 4.1.3 (Status Messages, level AA) asks that status messages can be determined through role or properties, so assistive technology presents them without receiving focus.

    Most silent failures come from timing. MDN says the element with the alert role must be present in the page first, which primes the browser and screen reader to watch it; a new element already holding its message generally does not lead to an announcement, because it is not a content change. MDN's aria-live page likewise shows an empty region updated later, and its alert example clears the text and then sets the message. So keep the status element in the page, empty, and write into it later.

    The lab turns that one documented rule into a function, announced(updates, { primed }). It is a model of the rule, not a screen reader; real products differ in what and when they speak:

    Expected output, captured from a real run (Node 26.13.1, 2026-12-01; section 3 of the demo):

    === 3. What a polite live region announces (one documented rule, not a screen reader)
      region in the page first, then text        -> "Delivery details saved"
      region created already holding the text    -> nothing
      same text set twice                        -> "Delivery details saved"
      text, cleared, same text again             -> "Delivery details saved", "Delivery details saved"

    Create the region already holding the message: nothing. Set the same text twice (a second "saved" click): once. Clear it in between: twice.

    Figure 3. Which tool for which change

    flowchart TD accTitle: Choosing focus, status or alert for a change on the page accDescr: A decision tree. If the user must act on the new content, move focus to it. Otherwise, if the user needs to know right away, such as a session about to expire, use an alert region sparingly. Otherwise, for a result, success or count message, write it into an existing polite status region and leave focus where it is. A{"Must the user act on
    the new content now?"} A -->|"yes"| F["Move focus to it
    (summary, first invalid field, dialog)"] A -->|"no"| B{"Does it need attention
    right away?"} B -->|"yes"| L["role alert, sparingly,
    present in the page before the text"] B -->|"no"| S["role status: write the text into
    an existing region, keep focus"]

    How to read this: the question is not how important the message is to you, but whether the user has to do something right now. Most messages ("saved", "3 results") are status messages.

    The search filters a list on every keystroke. The model writes a short status message from the count, so the change is reported without moving focus:

    Expected output, captured from a real run (Node 26.13.1, 2026-12-01; section 4 of the demo):

    === 4. Results status while a shopper types
      query ""      3 results -> ""
      query "o"     3 results -> "3 products found"
      query "oat"   2 results -> "2 products found"
      query "oatz"  0 results -> "No products found for \"oatz\""

    The empty box says nothing; "No products found" is words, not a blank list; and the component test checks that focus stays in the search box. WCAG's Understanding page gives "18 results returned" as an example of a status message and says the list of results is not one. A production version would debounce the message (see Debouncing and Throttling); the lab does not.

    What you can and cannot test here

    A jsdom test can check the name, description and invalid state a screen reader would be given, that the status element exists before it has text, and where focus is. It cannot show that anything is announced or how it sounds in NVDA, JAWS, VoiceOver or TalkBack. This lesson did not test with any screen reader.

    Trade-offs

    Choice Gain Cost
    Label with for and id Name, bigger click target An id for every control
    Hint and error through aria-describedby Read with the control Id order matters; stale ids must go
    Focus the first invalid field Fastest path to fixing The user may not hear how many problems exist
    Focus an error summary Count and list first One more step; the links must work
    Polite status region Announces without taking focus Must be present early; can be chatty
    role="alert" Prompt announcement Disruptive when overused

    Build it

    The lab is examples/frontend/labs/accessible-forms-model: a pure core (formModel.ts), thin React (DeliveryForm, NaiveEmailField, ProductSearch), 33 tests and the demo shown above.

    cd examples/frontend/labs/accessible-forms-model
    ../../node_modules/.bin/vitest run
    node src/demo.ts

    Verified. The 33 tests passed (20 on the model, 13 rendering the components in jsdom) with Node 26.13.1, Vitest 5.1.0 and React 19.3.1, and the demo output above is the golden file examples/frontend/golden/accessible-forms-model.txt. The validation rules are illustrative. The tests read roles, names, descriptions and focus; they heard nothing, and no real browser or screen reader was used.

    In practice: the delivery form at checkout

    NOTE

    This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.

    The situation

    The delivery form uses placeholder text as its only labels, shows one red "Please check your details" line at the top and keeps focus on the Save button. Support hears that screen-reader users "cannot tell which box is which" and that other users cannot find the field that failed.

    Starting architecture

    Figure 4. Placeholders and one generic error

    Starting architecture: unlabeled fields and one generic messageDelivery form to Validation (submit); Validation to Red banner (failed)Delivery form: placeholders as labelsDelivery formplaceholders aslabelsValidation: one failure flagValidationone failure flagRed banner: Please check your detailsRed bannerPlease check yourdetailssubmitfailed

    How to read this: the warning boxes are the gaps. The fields have no programmatic names, and the failure is one message that names no field and does not move focus.

    Options considered

    Option What it fixes What it costs
    A visible label on each field Names, larger click target A layout change
    Per-field errors with aria-describedby Errors read with the field An id scheme and clean-up
    An error summary with links, focus moved to it Count, list and a path to each field One more component
    A shared field component One tested pattern for every form A refactor

    The decision

    Field Decision record
    Context Unlabeled fields; a generic error; focus stays on the button.
    Decision A shared field component renders label, hint and error and derives aria-describedby and aria-invalid from the field spec. Messages say what is wrong and how to fix it. After a failed submit, show a summary and focus it. An always-present status region confirms success.
    Consequences Names and errors are programmatic and tested once. More markup and more copy to write.
    Revisit when Fields are grouped (addresses), the form becomes multi-step, or validation moves to the server.

    Rollout and verification

    1. Write the message copy and the field spec before the component.
    2. Test model and component: name, description, invalid state, focus target, status region present and empty.
    3. Walk the form by keyboard alone, then with a screen reader your users have.
    4. Check the error clears: fix a field and submit again; the old error id must leave aria-describedby.

    The 2 a.m. failure

    A change renders the status region only after a save succeeds. Success stops being announced, because the region is created already holding its text. Manual tests that only look at the screen do not notice.

    First three checks: (1) is the live region in the page before its text changes; (2) is the same message set twice without clearing; (3) did a refactor remount the region. Mitigation: render the region unconditionally. Follow-up: the lab's "keeps an empty status region in the page" test.

    Architect's notes

    • Make the accessible field the default: label, hint, error and ids live in one component, so a form cannot forget them.
    • Move focus only when the user must act; otherwise write a status message.
    • Write errors for the person fixing them: the field, the problem and the fix, in text.
    • Say what you tested. A jsdom test of names and focus is useful; it is not a screen-reader test.

    Common mistakes

    • Placeholder text as the only label.
    • An error with no link to its field, or shown only in red.
    • aria-invalid="true" on load, and one generic "please check your details".
    • A status region created together with its message.
    • role="alert" for everything, and ids in aria-describedby that point at removed elements.

    Key takeaways

    • A control's name comes from its label; hints and errors are linked with aria-describedby and read as its description.
    • Set aria-invalid after validation; write errors that say what is wrong and how to fix it.
    • After a failed submit, focus the first invalid field or a summary, on purpose.
    • For changes without a page load: focus if the user must act, an existing role="status" for news, role="alert" rarely.
    • A jsdom test can read names, descriptions and focus; it cannot hear anything.

    Practice exercises

    Exercise 1: Starter (30 min). Add a "Postcode" field to DELIVERY_FIELDS with a hint and a rule, and test its description before and after an error.

    Exercise 2: Intermediate (2 hours). Clear a field's error when the user edits it, and write a test that the error id leaves aria-describedby.

    Exercise 3: Advanced (half day). Add a fieldset with a legend for a delivery address, choose an error strategy for the group, and list what only a real screen reader could verify.

    In this course:

    Planned in this module, named as plain text: Accessibility Fundamentals and WCAG, Semantic HTML, ARIA and Accessible Names.

    Official documentation

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments