Sub topic 6
Making forms and pop-ups accessible
An inaccessible sign-up form loses subscribers you can't see. Visitors who use a screen reader, navigate by keyboard, use voice control, or zoom to 400% can't subscribe if the form blocks them. This chapter covers the working model and the common errors. It assumes you know basic HTML, a little JavaScript, and the form and <dialog> markup from the earlier chapters.
What accessibility means for a sign-up form
Most requirements come from the Web Content Accessibility Guidelines (WCAG) 2.2, level AA. Four ideas cover almost every failure in sign-up forms:
- Every control has a programmatic name. Assistive technology reads the name from a
<label>, not from nearby text or a placeholder. - Everything works from the keyboard. A visitor must be able to reach, operate, and leave every control with Tab, Shift+Tab, Enter, Space, and Escape.
- Changes are announced. Errors, success messages, and newly opened pop-ups must reach screen reader users, not only sighted ones.
- Nothing hides or traps. A pop-up must not cover the content the visitor is using or lock them in.
Labels, names, and autocomplete
A visible <label> linked with for and id is the most reliable name. It also enlarges the click target, because clicking the label focuses the field.
A placeholder is not a label. It disappears when the visitor types, usually has low contrast, and some screen readers skip it. Use placeholders only for hints such as an example format, never as the only name.
Add autocomplete="email" to the email field. WCAG 1.3.5 (Identify Input Purpose) requires a machine-readable purpose for fields that collect personal data. It also lets the browser fill the address in one tap, which helps motor-impaired users and raises conversion for everyone.
Use the right type. type="email" brings up the email keyboard on phones and provides basic validation. Do not set inputmode or pattern to override it unless you have a reason.
Instructions, errors, and status messages
Errors are where most forms fail. A red border alone fails WCAG 1.4.1 (Use of Color) and tells a screen reader user nothing. Each error needs text, placed next to the field and tied to it in code.
The pattern has four parts:
- Describe the problem in text ("Enter an address like [email protected]").
- Link the message to the field with
aria-describedby. - Set
aria-invalid="true"on the field. - Put the message in a live region so it is announced when it appears.
<form id="signup" action="https://example.com/subscribe" method="post" novalidate>
<label for="email">Email address</label>
<input type="email" id="email" name="email" autocomplete="email"
required aria-describedby="email-hint email-error">
<p id="email-hint">We send one email a week.</p>
<p id="email-error" role="alert"></p>
<label>
<input type="checkbox" name="consent" value="yes" required>
I agree to receive the weekly newsletter and can unsubscribe at any time.
</label>
<button type="submit">Subscribe</button>
</form>
<script>
const form = document.querySelector('#signup');
const email = document.querySelector('#email');
const error = document.querySelector('#email-error');
form.addEventListener('submit', (event) => {
if (!email.validity.valid) {
event.preventDefault();
error.textContent = email.validity.valueMissing
? 'Enter your email address.'
: 'Enter an address like [email protected].';
email.setAttribute('aria-invalid', 'true');
email.focus();
} else {
error.textContent = '';
email.removeAttribute('aria-invalid');
}
});
</script>Three details in this code matter:
novalidateturns off the browser's own bubbles, whose wording and screen reader support vary. Your own messages are consistent and can be styled.role="alert"makes the container a live region. It is empty at load and filled on error, which is when assistive technology announces it. A region that already contains text at page load is not announced.- Moving focus to the first invalid field with
email.focus()puts the visitor where the fix is needed. With several errors, move focus to the first and list the rest.
The same rule applies to the result. After a successful AJAX submit, write the confirmation ("Check your inbox to confirm") into a live region such as role="status". This satisfies WCAG 4.1.3 (Status Messages). If the form posts to a new page, give that page a clear <h1> and <title>.
The consent checkbox
The consent checkbox from the compliance rules must also be accessible. Wrap the checkbox and its sentence in one <label>, so the whole sentence is the clickable name. Keep the checkbox unticked. Place any link to the privacy policy inside the label text with descriptive wording ("privacy policy", not "click here"), and avoid hiding the required consent behind a tiny, low-contrast line.
Pop-ups as modal dialogs
A pop-up that covers the page is a modal dialog. A modal dialog has to do four things:
- Move focus into itself when it opens.
- Keep keyboard focus inside while open.
- Close with Escape and with a visible button.
- Return focus to where the visitor was when it closes.
The native <dialog> element opened with showModal() does all four. It also makes the rest of the page inert, so screen readers and the Tab key can't reach the background. Prefer it over a <div> with role="dialog", which needs a focus trap and aria-modal handling written by hand.
Give the dialog a name with aria-labelledby pointing at its heading, as in the earlier example. A dialog without a name is announced only as "dialog".
Use the autofocus attribute on the control you want focused first. By default, browsers focus the first focusable element. If your dialog opens with a close button first, that is acceptable. If the dialog is long, focus the heading instead so the visitor hears the context first.
<dialog id="signup-dialog" aria-labelledby="signup-title">
<h2 id="signup-title">Get the free checklist</h2>
<form action="https://example.com/subscribe" method="post">
<label for="popup-email">Email address</label>
<input type="email" id="popup-email" name="email" autocomplete="email" required autofocus>
<button type="submit">Send it to me</button>
</form>
<form method="dialog">
<button>No thanks</button>
</form>
</dialog>Pop-ups that open by themselves
A pop-up that opens on a timer or scroll interrupts whatever the visitor was doing. For a screen reader user, it moves focus without warning. Two guidelines apply:
- WCAG 2.2.1 (Timing Adjustable) and 3.2.1 (On Focus) favor changes the user starts. A scroll or exit trigger is acceptable, but a pop-up that appears within the first seconds, before the visitor has read anything, is the worst case.
- Never reopen a pop-up right after the visitor closes it. The frequency cap from the scroll-trigger example is an accessibility feature as well as a courtesy.
Offer an alternative that does not interrupt: an inline form in the page content, reachable by heading or landmark, so a visitor who dismissed or never saw the pop-up can still subscribe.
Sticky bars, slide-ins, and focus visibility
Fixed elements can hide what has keyboard focus. WCAG 2.4.11 (Focus Not Obscured) requires that a focused control is not entirely covered by sticky content. A fixed bottom bar can cover the field the visitor is tabbing to. Add scroll-padding-bottom equal to the bar height on the html element so the browser scrolls focused items clear of it.
Check these as well:
- Close control: The dismiss button needs a text name. If it shows only an "×", add
aria-label="Close". - Target size: WCAG 2.5.8 requires interactive targets of at least 24 by 24 CSS pixels. Aim for 44 by 44 on mobile, where tiny close buttons are a common failure.
- Contrast: Text needs a 4.5:1 ratio against its background and focus outlines 3:1. White text over a photo background is a frequent failure.
- Zoom and reflow: At 400% zoom (a 320 pixel-wide viewport), the pop-up must scroll or reflow without hiding its close button.
- Motion: Respect
prefers-reduced-motionfor slide-in animation, and do not auto-rotate content.
The honeypot field
A honeypot (the hidden field from the spam chapter) is invisible to sighted users but can reach assistive technology if you hide it carelessly. Use all three of these: aria-hidden="true" on the wrapper, tabindex="-1" on the input, and autocomplete="off". Do not use display:none plus a label that says "leave empty" without hiding it from the accessibility tree, because a screen reader user could then fill it in and be rejected as a bot. If you use a CAPTCHA instead, offer a non-visual alternative, since WCAG 3.3.8 (Accessible Authentication) and general guidance discourage tests that depend on a single sense or on solving puzzles.
Testing
Automated checkers catch roughly a third of the problems, so combine methods:
- Unplug the mouse and subscribe with only the keyboard. Check that focus is always visible and that it returns after the dialog closes.
- Run an automated checker such as axe DevTools or Lighthouse on the page with the dialog open.
- Turn on a screen reader (VoiceOver, NVDA, or TalkBack) and listen to the label, hint, error, and success text.
- Zoom the browser to 400% and rotate a phone to landscape.
Common mistakes
| Mistake | Effect | Fix |
|---|---|---|
| Placeholder used as the only label | Field has no name once text is typed | Add a visible `<label>` |
| Error shown only in red | Fails for color-blind and screen reader users | Add text and `aria-describedby` |
| `<div>` pop-up with no focus handling | Keyboard focus stays behind the overlay | Use `<dialog>` with `showModal()` |
| Close button with only "×" | Announced as "button" | Add `aria-label="Close"` |
| Pop-up on page load | Interrupts before the visitor engages | Use a scroll or exit trigger plus a cap |
| Sticky bar over focus | Focused field is hidden | Set `scroll-padding-bottom` |
Exercise
A visitor who uses a screen reader submits your pop-up form with a missing email address. The page shows a red border on the field but the visitor hears nothing and does not know why the form did not send. Name two changes that fix this.
Show answer
First, add an error message in text, linked to the field with aria-describedby, and set aria-invalid="true" on the field. Second, put the message in a live region (for example role="alert") so it is announced when it appears, and move focus to the invalid field. The red border alone is not enough, because it relies on color and is not exposed to assistive technology.
Exercise
Why is a native <dialog> opened with showModal() usually a safer choice than a <div> styled as a pop-up?
Show answer
showModal() moves focus into the dialog, makes the rest of the page inert so Tab cannot reach it, closes on Escape, and returns focus to the previously focused element when the dialog closes. A <div> needs all of that built and tested by hand.