Module 05 · Lesson 5.5
Accessibility Basics for Forms
On this page
- What you will learn
- What accessibility means, and how to label a form
- Showing errors to everyone: summary, aria-describedby and aria-invalid
- Keyboard use, visible focus and colour contrast
- Worked scenario: the Tidewell accessibility check record
- Step-by-step workflow
- What the assistant can and cannot do for accessibility
- Conclusion and your next step
- Reusable prompt
- Expected output
- Common errors and fixes
- Validation checklist
- Hands-on exercise
- Knowledge check
- Frequently asked questions
- References
Imagine a form where the questions are written in pale grey ink, the pen only works for people with steady hands, and a mistake is marked with a small red dot and no words. Some people could still fill it in. Many could not. A web form can fail people in the same ways, and the fixes are mostly simple.
In this lesson you make Tidewell's booking form usable by everyone. You label every field, group the time choices, show errors in words that a screen reader announces, and check that the form works with a keyboard alone. You also test colour contrast with a small function and finish with an accessibility check record, which is a deliverable of this module.
What you will learn
- Label fields and group related choices with native HTML elements.
- Show errors with an error summary, aria-describedby and aria-invalid, so everyone is told.
- Check keyboard use, visible focus, phone width and text contrast against the 4.5:1 rule.
- Keep an accessibility check record, and use an assistant to review a component without trusting it blindly.
Before you start
- Completed Loading, Empty and Error States, or have screens with states of your own.
- Access to any capable AI assistant.
- Optional: Node.js and the project from earlier lessons, if you want to run the examples.
What accessibility means, and how to label a form
Accessibility means that people with different abilities and tools can use your screens. Some people cannot see the screen and use a screen reader. Some cannot use a mouse. Some have low vision or colour blindness. Some are simply on a phone in bright sunlight. Good accessibility helps all of them.
The standard most teams follow is the Web Content Accessibility Guidelines, or WCAG. Level AA of version 2.2 is a common target, and it is the one used in this course. Read it in the WCAG 2.2 recommendation (opens in a new tab). You do not need to memorise it. You need a few habits.
- Screen reader
- Software that reads the screen aloud or turns it into braille. Like a friend reading a letter to you: it can only read what is written, so unlabelled things are skipped.
- Label
- The text tied to a form field that says what the field is for. Like the sticker on a drawer.
- Fieldset and legend
- A box that groups related fields, with a title. Like a heading above a set of tick boxes on a paper form.
- ARIA attribute
- An extra HTML attribute that gives assistive software information the plain HTML cannot, such as which text describes a field. Use it to add detail, not to replace native elements.
- Contrast ratio
- A number that says how different two colours are in brightness, from 1:1 (identical) to 21:1 (black on white). Like the difference between chalk on a blackboard and chalk on white paper.
The first habit is to use native elements. A button can be reached with the keyboard and announced as a button without any extra work. A div with a click handler cannot. The same is true of label, fieldset and input.
The slot choice on screen S1 is a set of radio buttons. Only one can be selected, and the group needs a name. A fieldset with a legend gives the group its name, so a screen reader says 'Choose a time, group' before it reads each option. Each radio has its own label, tied to it by matching htmlFor and id.
export function SlotChoiceForm({ slots, errors, selectedSlotId, submitting = false, onSubmit }: SlotChoiceFormProps) {
const slotError = errors.find((e) => e.field === "slotId");
return (
<form onSubmit={onSubmit} noValidate>
<ErrorSummary errors={errors} />
<fieldset aria-describedby={slotError ? "slotId-error" : undefined}>
<legend>Choose a time</legend>
{slotError && (
<p id="slotId-error" className="field-error">
<span className="visually-hidden">Error: </span>
{slotError.message}
</p>
)}
{slots.map((slot, index) => {
const id = index === 0 ? "slotId" : "slotId-" + index;
return (
<div key={slot.slotId} className="choice">
<input type="radio" id={id} name="slotId" value={slot.slotId} defaultChecked={slot.slotId === selectedSlotId} />
<label htmlFor={id}>
{formatTime(slot.startsAt)} to {formatTime(slot.endsAt)}
</label>
</div>
);
})}
</fieldset>
<button type="submit" disabled={submitting}>
{submitting ? "Booking" : "Book this time"}
</button>
</form>
);The form component, without its imports and prop types. It uses the ErrorSummary shown in the next section.
What each part does
<fieldset>and<legend>group the radios and name the group.- Each
<input type="radio">has a<label htmlFor=...>with the same id. Clicking the label selects the radio, which also gives a bigger tap target on a phone. - The first radio gets the id
slotId. The error summary links to that id, so the link lands on the first choice. noValidateturns off the browser's own pop-up bubbles, so our consistent error summary does the job.- The button is a real
buttonwithtype="submit". It is the last thing in the tab order, and Enter works on it.
<form novalidate="">
<fieldset>
<legend>Choose a time</legend>
<div class="choice">
<input type="radio" id="slotId" name="slotId" value="12"/>
<label for="slotId">09:00 to 09:45</label>
</div>
<div class="choice">
<input type="radio" id="slotId-1" name="slotId" checked="" value="13"/>
<label for="slotId-1">10:00 to 10:45</label>
</div>
<div class="choice">
<input type="radio" id="slotId-2" name="slotId" value="14"/>
<label for="slotId-2">11:00 to 11:45</label>
</div>
</fieldset>
<button type="submit">Book this time</button>
</form>Read the output the way a screen reader would. A group called 'Choose a time'. Three radios, each with its own label. A button. Nothing is hidden behind a picture or a colour.
Showing errors to everyone: summary, aria-describedby and aria-invalid
An error shown only as a red border is invisible to some people and unheard by others. Good form errors do four things. They say what is wrong in words. They are placed next to the field. They are tied to the field in code. And a summary at the top announces them and lets the person jump to each one.
- Error summary: a box at the top that lists every problem, each as a link to its field. It has
role="alert"and receives focus when it appears, so a screen reader reads it at once. - aria-describedby: an attribute on a field that points to the id of the text that describes it, such as a hint or an error. The reader says that text after the label.
- aria-invalid: an attribute that tells assistive software the field's value is not acceptable.
export function ErrorSummary({ errors }: { errors: FieldError[] }) {
const box = useRef<HTMLDivElement>(null);
useEffect(() => {
if (errors.length > 0) box.current?.focus();
}, [errors]);
if (errors.length === 0) return null;
return (
<div ref={box} role="alert" tabIndex={-1} className="error-summary">
<h2>There is a problem</h2>
<ul>
{errors.map((error) => (
<li key={error.field}>
<a href={"#" + error.field}>{error.message}</a>
</li>
))}
</ul>
</div>
);
}A client component, because it uses hooks to move focus.
What each part does
useRefgives access to the summary box. TheuseEffectruns after the box appears and callsfocus()on it.tabIndex={-1}lets code move focus to the box without adding it to the normal tab order.role="alert"makes screen readers announce the box when it appears.- Each error is a link to
#plus the field name, so Tab and Enter take the person to the field. For slot choice, the field name isslotId, the id of the first radio. - If there are no errors, the component returns
null, so nothing is drawn.
Now a single field. S1 also needs a date. DateField ties a label, a hint and an error to one input.
export function DateField({ id, label, hint, error, value }: DateFieldProps) {
const hintId = id + "-hint";
const errorId = id + "-error";
const describedBy = [hint ? hintId : "", error ? errorId : ""].filter(Boolean).join(" ");
return (
<div className="field">
<label htmlFor={id}>{label}</label>
{hint && (
<p id={hintId} className="hint">
{hint}
</p>
)}
{error && (
<p id={errorId} className="field-error">
<span className="visually-hidden">Error: </span>
{error}
</p>
)}
<input
id={id}
name={id}
type="date"
defaultValue={value}
aria-invalid={error ? true : undefined}
aria-describedby={describedBy || undefined}
/>
</div>
);
}Here is what it renders with no error, and then with the error 'Choose a date.' In the second case the input gains aria-invalid. Its aria-describedby then lists both the hint and the error.
== DateField plain ==
<div class="field">
<label for="date">Date</label>
<p id="date-hint" class="hint">For example, 01 12 2026</p>
<input id="date" name="date" type="date" aria-describedby="date-hint"/>
</div>
== DateField error ==
<div class="field">
<label for="date">Date</label>
<p id="date-hint" class="hint">For example, 01 12 2026</p>
<p id="date-error" class="field-error">
<span class="visually-hidden">Error: </span>Choose a date.</p>
<input id="date" name="date" type="date" aria-invalid="true" aria-describedby="date-hint date-error"/>
</div>The hidden text 'Error: ' in the error paragraph is read by a screen reader, so it cannot be mistaken for a hint. The visually-hidden class hides it on screen and keeps it for assistive software. Here is the form with an error on it. The summary comes first, the message sits above the group, and the fieldset points to it.
<form novalidate="">
<div role="alert" tabindex="-1" class="error-summary">
<h2>There is a problem</h2>
<ul>
<li>
<a href="#slotId">Choose a time before you continue.</a>
</li>
</ul>
</div>
<fieldset aria-describedby="slotId-error">
<legend>Choose a time</legend>
<p id="slotId-error" class="field-error">
<span class="visually-hidden">Error: </span>Choose a time before you continue.</p>
<div class="choice">
<input type="radio" id="slotId" name="slotId" value="12"/>
<label for="slotId">09:00 to 09:45</label>
</div>
<div class="choice">
<input type="radio" id="slotId-1" name="slotId" value="13"/>
<label for="slotId-1">10:00 to 10:45</label>
</div>
<div class="choice">
<input type="radio" id="slotId-2" name="slotId" value="14"/>
<label for="slotId-2">11:00 to 11:45</label>
</div>
</fieldset>
<button type="submit">Book this time</button>
</form>Note the difference between the two forms. A single input, such as the date, gets aria-invalid and aria-describedby on the input itself. A group of radios gets aria-describedby on the fieldset, because the error belongs to the whole group.
Keyboard use, visible focus and colour contrast
Keyboard use means the whole form can be completed without a mouse. Tab moves to the next control, Shift and Tab move back, arrow keys change the choice inside a radio group, and Enter or Space press a button. Native elements do all of this for you. Custom ones usually do not.
People using a keyboard need to see where they are. That is called focus. Do not remove the outline that browsers draw around the focused control. If you restyle it, make it clearer, not weaker.
:focus-visible {
outline: 3px solid #0b5cad;
outline-offset: 2px;
}
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}Two small style rules. They are plain CSS and are not run by the tests in this lesson.
Colour is the third habit. For normal text, WCAG sets the lowest allowed ratio at 4.5 to 1. For large text it is 3 to 1. Large means about 24 pixels, or about 19 pixels when bold. The reasoning is on the page Understanding Contrast (Minimum) (opens in a new tab). You can check this with a small function and no design tool.
function channel(value: number): number {
const s = value / 255;
return s <= 0.04045 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
}
export function relativeLuminance(hex: string): number {
const match = /^#([0-9a-f]{6})$/i.exec(hex);
if (!match) throw new Error("Expected a colour like #1a2b3c, got: " + hex);
const n = parseInt(match[1], 16);
return 0.2126 * channel((n >> 16) & 255) + 0.7152 * channel((n >> 8) & 255) + 0.0722 * channel(n & 255);
}
export function contrastRatio(foreground: string, background: string): number {
const a = relativeLuminance(foreground);
const b = relativeLuminance(background);
return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
}
export function passesAA(foreground: string, background: string, largeText = false): boolean {
return contrastRatio(foreground, background) >= (largeText ? 3 : 4.5);
}What each part does
channelconverts one colour channel from the screen's scale to a linear brightness. The formula comes from the WCAG definition of relative luminance.relativeLuminancereads a colour such as#0b5cadand combines the three channels. Green counts most, because the eye is most sensitive to it.contrastRatiocompares the lighter and the darker colour. The order of the arguments does not matter.passesAAapplies the 4.5 limit, or 3 for large text. It compares the exact number, so 4.499 does not pass.
Pair Ratio Normal text (4.5) Large text (3)
Black on white 21.00 pass pass
Body text on white 14.75 pass pass
Link blue on white 6.66 pass pass
Hint grey on white 4.54 pass pass
Slightly lighter grey 4.47 FAIL pass
Placeholder grey 2.61 FAIL FAIL
White on teal button 5.47 pass pass
White on light teal button 1.86 FAIL FAIL
all contrast checks passedThe results are worth reading closely. Grey #767676 on white just passes at 4.54. The slightly lighter #777777 is about 4.47 and fails for normal text. The table shows rounded-down values, because a rounded-up 4.50 could hide a fail. White text on the light teal button is 1.86, so it fails even as large text.
Phone width matters too. Tidewell's criterion NFR-02 says every step must work at 360 pixels wide without sideways scrolling. WCAG's reflow rule is stricter, at 320 pixels. Use native controls, let text wrap, and test by narrowing the browser window or using its device mode.
Worked scenario: the Tidewell accessibility check record
A module deliverable is an accessibility check record: a short, dated table of what was checked, how and with what result. It is evidence for the client and a to-do list for you. Be honest in it. 'Not yet checked' is a better entry than a guess.
For Tidewell the check covers screens S1 to S5. The colour check was run with the function above. The other checks are done by hand when the screens are running in a browser.
# Accessibility check record: Tidewell booking screens
Standard: WCAG 2.2 level AA. Screens: S1 to S5. Date started: 2026-11-19.
| Check | How | Result |
|-------|-----|--------|
| Keyboard only | Complete booking, move and cancel using Tab, Shift+Tab, arrows, Enter and Space | Not yet checked |
| Labels | Every field has a visible label; radio groups have a legend | Not yet checked |
| Errors | Submit with no time chosen; summary appears, takes focus, links work | Not yet checked |
| Contrast | contrastRatio on text and background pairs | Body text on white 14.75; link blue 6.66; hint grey 4.54 (all pass). Remaining pairs not yet checked |
| Phone width | Narrow the window to 360 px; no sideways scrolling on any step | Not yet checked |
| Focus visible | The focus outline is clearly visible on every control | Not yet checked |
Not checked by this record: screen reader testing with real assistive software. Plan that with the practice manager.A record in the making. Only the contrast line has a result, because it is the only check run by a script so far.
The last line is important. These checks catch many problems, but they do not replace testing with real assistive software and, when possible, with real users. The record says what was and was not covered, so nobody believes more than the evidence supports.
Tidewell's patients include people who book by phone today. An accessible booking page is not a favour. It is part of making the new system available to the same people who use the old one.
Step-by-step workflow
Step 1: Use native elements first
Check that every action is a button, every link is a link, every field is an input with a label and every group of choices is a fieldset with a legend.
What you should see: No clickable divs and no unlabelled fields.
Step 2: Tie errors to fields
Show an error summary that takes focus, put a message by each field and add aria-describedby and aria-invalid.
What you should see: Every error is in words, near the field and linked in code.
Step 3: Walk the form with the keyboard
Put the mouse away. Tab through the whole flow, choose with the arrows and submit with Enter. Check the focus is always visible and never trapped.
What you should see: A booking made with the keyboard alone.
Step 4: Check contrast and phone width
Run the contrast function on every text and background pair. Narrow the window to 360 pixels and use each step.
What you should see: A list of passes and fails with the numbers.
Step 5: Ask an assistant to review one component
Use the prompt card. Treat its answer as a list of things to verify yourself, not a certificate.
What you should see: A short list of suspected issues, each checked by you.
Step 6: Fill in the record
Write each result in docs/accessibility-check.md with the date. Mark anything you did not test as 'Not yet checked'.
What you should see: A dated, honest accessibility check record.
- Native elements
Label, fieldset, button
- Errors
Summary and aria-describedby
- Keyboard
Tab through it
- Contrast and width
4.5:1 and 360 px
- Assistant review
Suspects, not proof
- Check record
Dated results
Native elements come first. The record comes last and says only what was tested.
What the assistant can and cannot do for accessibility
An assistant can spot a missing label or a div acting as a button within seconds. It can also say a component is 'fully accessible' when it never ran it. It cannot hear a screen reader, feel a focus trap or see a faint grey on a sunny phone.
| Task | Assistant's part | Your part |
|---|---|---|
| Reviewing a component | List likely issues: labels, roles, focus, contrast. | Check each by running the component, the keyboard and the contrast function. |
| Writing form code | Draft it with native elements and ARIA. | Check it uses ARIA only where native elements cannot do the job. |
| Wording errors | Suggest plain messages. | Check they say what is wrong and how to fix it. |
| Claiming compliance | Nothing. It cannot certify. | Record only what you tested, and test with real assistive software later. |
| Choosing a standard | Nothing. | Agree the target level with the client. |
Conclusion and your next step
Accessible forms come from a few habits. Use native elements. Label every field and group related choices. Write errors, link them and announce them. Let the keyboard reach everything, and keep colours strong enough. A dated check record says what you tested and what you did not.
Your next step: run the keyboard, label, contrast and phone-width checks on one of your own forms and fill in your accessibility check record. Then finish the module assignment, and move on to Authentication and Integrations, where you add sign-in, roles and an outside service.
The Accessibility Review of a UI Component prompt gives an assistant a structured way to review a component. The Frontend and API Integration module page lists the assignment and checklist you can use to finish this module.
Reusable prompt
Form accessibility reviewer
Asks an assistant to review one form component for accessibility problems and to say how you can verify each one.
You are reviewing one form component for accessibility against WCAG 2.2 level AA. Do not rewrite the whole component and do not claim it is compliant.
Project: Tidewell Physiotherapy booking system (fictional). React in a Next.js App Router project. Component: SlotChoiceForm, a radio group where a patient chooses one free time, with an error summary.
Code:
[paste the full contents of src/components/SlotChoiceForm.tsx and src/components/ErrorSummary.tsx here]
Check these points and answer for each: label for every field, fieldset and legend for the radio group, error text linked with aria-describedby, aria-invalid where it applies, error summary with role="alert" that receives focus, keyboard order and use, visible focus, use of native elements, and any ARIA that is wrong or unneeded.
Rules:
1. List only problems you can point to in the code. Quote the line.
2. For each problem say how I can verify it myself (for example, "Tab through the form" or "run the contrast function").
3. Mark every finding "Proposed". Do not invent colours or contrast numbers.
4. End with a list of what you cannot judge from code alone, such as screen reader behaviour and colour.Show the reusable template
Replace each {{placeholder}} with your own details.
You are reviewing one form component for accessibility against WCAG 2.2 level AA. Do not rewrite the whole component and do not claim it is compliant.
Project: {{project_and_stack}}. Component: {{component_name_and_purpose}}.
Code:
{{paste_the_component_here}}
Check these points and answer for each: label for every field, fieldset and legend for groups, error text linked with aria-describedby, aria-invalid where it applies, error summary behaviour, keyboard order and use, visible focus, use of native elements, and any ARIA that is wrong or unneeded.
Rules:
1. List only problems you can point to in the code. Quote the line.
2. For each problem say how I can verify it myself.
3. Mark every finding "Proposed". Do not invent colours or contrast numbers.
4. End with a list of what you cannot judge from code alone.Expected output and limitations
A short list of findings, each pointing to a line of your code, marked Proposed and paired with a way to verify it. It ends with what cannot be judged from code, such as screen reader behaviour and colour.
Proposed: the button is disabled while submitting.
Line: <button type="submit" disabled={submitting}>
Why it may matter: a disabled button cannot receive focus, so a keyboard user loses their place.
Verify: submit with the keyboard and see where focus goes.
Proposed: the first radio uses id "slotId" and the rest "slotId-1", "slotId-2".
This is fine for the error link. Verify: press the link in the summary and check focus lands on the first radio.
Cannot judge from code alone:
- how a screen reader announces the group and the error
- colour contrast of the text and the focus outline
- behaviour at 360 px wideLimitations to keep in mind
- The assistant reads code. It does not run a screen reader, press keys or measure colour, so its list is a set of suspects.
- It may recommend extra ARIA that conflicts with native elements. Prefer the native element, and check the advice against the WCAG pages.
- It may say the component 'meets WCAG'. Ignore it: only your own checks and real assistive software testing support a claim.
Common errors and how to fix them
A field has a placeholder but no label.
Why it happens: The placeholder looked like a label on screen.
Fix: Add a visible label tied to the input. A placeholder disappears when typing and is not a label.
Errors are shown only as a red border.
Why it happens: Colour was treated as enough.
Fix: Write the error in words, place it by the field and link it with aria-describedby. Add the error summary.
The focus outline was removed because it looked untidy.
Why it happens: A style rule set the outline to none.
Fix: Keep a clear, visible outline for keyboard focus, and check it has enough contrast.
Validation checklist
Tick each item once you have confirmed it.
Hands-on exercise
An accessible Ferngate parts form
Ferngate Cycle Repairs has a form for recording a part taken for a job, with a job number, a part number and a quantity. Build the form with an assistant, review it, and write an accessibility check record for it.
You will need
- Fields: job number (text), part number (text) and quantity (number).
- Note: mechanics use a shared tablet with greasy hands, so tap targets and text must be large.
- Note: the workshop lighting is bright, so colour contrast matters.
- Note: the server returns the problem format with a list of field errors.
Acceptance criteria
Your work is done when every one of these is true.
Hints (2)
- A grey hint text is a classic contrast failure. Run the contrast function on yours.
- A shared tablet is used standing up. Think about the size of the tap targets and about error text that is easy to read.
Show a model answer
A strong answer has three labelled inputs, each in its own wrapper with a hint and an error paragraph, and a summary at the top that takes focus on a failed submit. The quantity field uses type number with a hint such as 'Enter a whole number from 1 to 20', and the range is marked as an assumption for the owner to confirm. The record shows the contrast numbers you measured, the keyboard walk-through result and the width check, and marks screen reader testing as not done. A rejected suggestion might be an aria-label on an input that already has a visible label, because two names for one field can confuse screen readers.
Knowledge check
Choose an answer, then check it. Nothing is recorded — this is for you.
Show the answer and explanation
Answer: B. A placeholder is a hint, not a label. It disappears as soon as someone types, and assistive software does not always treat it as the field's name. A darker colour is tempting because contrast is a real issue, but it does not fix the missing label.
Show the answer and explanation
Answer: B. It links the field to the text that describes it, which the reader announces after the label. It has no visual effect, which is why red borders alone are tempting but not enough. It also does not block submission.
Show the answer and explanation
Answer: B. The limit is a hard number and 4.47 is below it. 'Close enough' is tempting, but a threshold is checked exactly, and people with low vision are the ones who need it. A white background is already counted in the ratio.
Frequently asked questions
What is accessibility in web forms?
It means that everyone can fill in the form, including people who use a keyboard, a screen reader or a magnifier. You get most of the way with native elements, a label on every field, grouped choices and clear errors. Then you check with a keyboard and a contrast tool.
What is the difference between a label and a placeholder?
A label is visible text tied to a field and stays on the screen. A placeholder is a hint inside the field that disappears when you type. Use a label for the name of the field, and keep placeholders for short examples, or leave them out.
How do I make form errors accessible?
Write each error in words and place it by its field. Link it to the field with aria-describedby and mark the field with aria-invalid. Add an error summary at the top that receives focus and links to each field.
What colour contrast ratio does WCAG AA require?
Normal text needs at least 4.5 to 1 against its background. Large text needs 3 to 1. You can measure it with a function like the one in this lesson, or with a browser tool. Do not round up: 4.47 is a fail.
- Written by
- PromptFable Editorial
- Last updated 19 Nov 2026
- Review
- Reviewed by Waseem Nadir, Technical Reviewer
- Last reviewed 27 Nov 2026
References
Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.
- Web Content Accessibility Guidelines (WCAG) 2.2(opens in a new tab)
W3C · Official documentation · The standard, including the contrast and reflow rules.
- Understanding Success Criterion 1.4.3: Contrast (Minimum)(opens in a new tab)
W3C Web Accessibility Initiative · Official documentation · Explains the 4.5:1 and 3:1 limits and the contrast formula.
- Forms Tutorial(opens in a new tab)
W3C Web Accessibility Initiative · Official documentation · Practical advice on labels, groups, instructions and error messages.
- Error summary(opens in a new tab)
GOV.UK Design System · Official documentation · A well-tested pattern for the summary box that this lesson's component follows in outline.
- aria-describedby(opens in a new tab)
MDN Web Docs · Official documentation · Reference for the attribute that links a field to its hint or error.
PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.