惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
Lohrmann on Cybersecurity
Martin Fowler
Martin Fowler
Engineering at Meta
Engineering at Meta
腾讯CDC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Azure Blog
Microsoft Azure Blog
G
Google Developers Blog
TaoSecurity Blog
TaoSecurity Blog
博客园_首页
Vercel News
Vercel News
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Last Week in AI
Last Week in AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
The Exploit Database - CXSecurity.com
量子位
Project Zero
Project Zero
A
Arctic Wolf
小众软件
小众软件
NISL@THU
NISL@THU
C
CERT Recently Published Vulnerability Notes
有赞技术团队
有赞技术团队
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Troy Hunt's Blog
P
Privacy & Cybersecurity Law Blog
Security Latest
Security Latest
B
Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
D
DataBreaches.Net
Schneier on Security
Schneier on Security
The Hacker News
The Hacker News
K
Kaspersky official blog
C
Check Point Blog
Hacker News: Ask HN
Hacker News: Ask HN
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Webroot Blog
Webroot Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
人人都是产品经理
人人都是产品经理
AI
AI
Cisco Talos Blog
Cisco Talos Blog
MyScale Blog
MyScale Blog
Cloudbric
Cloudbric
B
Blog RSS Feed
S
Schneier on Security
P
Palo Alto Networks Blog

TetraLogical Blog

Designing for people with reading disabilities - TetraLogical Designing for people who are D/deaf - TetraLogical Designing accessible documents - TetraLogical Introduction to creating accessible documents - TetraLogical Inclusive user research: vulnerable people - TetraLogical Designing for people who are blind - TetraLogical Designing for people with low vision - TetraLogical Meet the team: Niamh Madden - TetraLogical Designing for people with anxiety - TetraLogical Designing for people with disabilities - TetraLogical Accessible building blocks for the web videos - TetraLogical Common accessibility misconceptions - TetraLogical Common misconceptions about testing accessibility - TetraLogical Common misconceptions about implementing accessibility - TetraLogical Common misconceptions about WCAG - TetraLogical Common misconceptions about disability - TetraLogical Meet the team: Grace Snow - TetraLogical Sustainable accessibility in complex organisations: strategic foundations - TetraLogical Sustainable accessibility in complex organisations: organisational realities - TetraLogical Sustainable accessibility in complex organisations: external factors - TetraLogical Common misconceptions about screen readers - TetraLogical Guide to the Inclusive Design Principles - TetraLogical Meet the team: Ian Lloyd - TetraLogical Annotating designs using common language - TetraLogical Meet the team: Catriona Morrison - TetraLogical Championing inclusive language - TetraLogical Press release: TetraLogical launches accessible self-led training courses to help digital teams build confidence in accessibility - TetraLogical Why inclusive products are green products - TetraLogical Accessible Recruitment - TetraLogical Accessibility and the agentic web - TetraLogical Meet the team: Craig Abbott - TetraLogical Foundations: types of assistive technology and adaptive strategies - TetraLogical European Accessibility Act (EAA) FAQ - TetraLogical Screen reader HTML support tables - TetraLogical Interview with Lola Odelola - TetraLogical Understanding EN 17161 Design for All - TetraLogical Inclusive user research: building rapport - TetraLogical Foundations: Keyboard accessibility - TetraLogical Can generative AI write contextual text descriptions? - TetraLogical Understanding the European Accessibility Act (EAA) - TetraLogical Meet Josh: a sportsman who has spinal muscular atrophy - TetraLogical Meet Jonathan: a photographer who has ADHD - TetraLogical Foundations: grouping forms with `<fieldset>` and `<legend>` - TetraLogical XR Accessibility: for people with moving disabilities - TetraLogical Meet Andre: a music producer and blind screen reader user - TetraLogical Foundations: types of disability - TetraLogical Meet Lauren: a film editor who has ADHD - TetraLogical Meet Steve: a photographer who is deaf and low vision - TetraLogical Meet Hasmukh: a blind cricketer and screen reader user - TetraLogical XR Accessibility: for people with hearing disabilities - TetraLogical XR Accessibility: for people with thinking disabilities - TetraLogical XR Accessibility: for people with seeing disabilities - TetraLogical Introduction to XR Accessibility - TetraLogical Foundations: labelling text fields with input and label - TetraLogical Design patterns and WCAG - TetraLogical Does WCAG 2.2 apply to native apps - TetraLogical Why are my live regions not working? - TetraLogical Building a culture of accessibility - TetraLogical When to use tabindex= Accessibility foundations - TetraLogical Meet the team: Demelza Feltham - TetraLogical Can generative AI help write accessible code? - TetraLogical Meet the team: Steve Faulkner - TetraLogical Meet the team: Gez Lemon - TetraLogical Keyboard accessibility myths and WCAG - TetraLogical Amendment to the Public Sector Accessibility Regulations - TetraLogical What Considerations for TV user interface accessibility - TetraLogical Meet the team: Alistair Duggin - TetraLogical Sticky content: focus in view - TetraLogical The only accessibility specialist in the room - TetraLogical Meet the team: Ian Pouncey - TetraLogical Meet the team: Dean Holden - TetraLogical Meeting WCAG Level AAA - TetraLogical Foundations: accessible names and descriptions - TetraLogical Inclusive XR: accessible augmented reality experiences - TetraLogical Foundations: pointer gestures - TetraLogical Meet the team: Graeme Coleman - TetraLogical Adding sign language to videos - TetraLogical Foundations: introduction to WAI-ARIA - TetraLogical Meet the team: Joe Lamyman - TetraLogical Inclusive XR: accessible 3D experiences - TetraLogical Foundations: visible focus styles - TetraLogical Foundations: target sizes - TetraLogical Meet the team: Henny Swan - TetraLogical Meet the team: Ela Gorla - TetraLogical Foundations: native versus custom components - TetraLogical Foundations: HTML semantics - TetraLogical Accessibility and supporting Internet Explorer - TetraLogical Meet the team: Felicity Miners-Jones - TetraLogical Accessibility and QR codes - TetraLogical Inclusive user research: recruiting participants - TetraLogical Research insight: accessibility of images - TetraLogical Meet the team: Léonie Watson - TetraLogical Android accessibility: roles and TalkBack - TetraLogical Accessible design systems - TetraLogical Meet the team: Patrick H. Lauke - TetraLogical Inclusive user research: analysing findings - TetraLogical How to write user stories for accessibility - TetraLogical Triaging WCAG 2.1 Level AAA - TetraLogical
Foundations: form validation and error messages - TetraLogical
2024-10-21 · via TetraLogical Blog

Posted on by Demelza Feltham in Design and development

Tags: Assistive Technology, Code, Foundations, WCAG

As well as labelling text fields with input and labels, and grouping forms with the <fieldset> and <legend> elements, form validation and error messages are also essential to making forms accessible to everyone.

Forms are crucial for interactive web experiences, but they can often lead to errors requiring validation. Inaccessible validation and feedback can cause frustration and can sometimes result in form abandonment. However, when made accessible, the process becomes seamless and frictionless.

This benefits everyone, but in particular:

  • People browsing with a screen reader and braille displays who cannot see content and rely on the properly coded form validation and error messages to progress with the form
  • People with cognitive disabilities who need clear and concise error feedback to understand the issue and how to fix it
  • People with reduced focus or short attention spans who rely on both clear in-line error messages and post-submission error notifications

Accessible form validation and error messages come in two forms, in-line error messages, and post-submission error messages.

In-line error messages

When filling out a form, real-time error messages can appear thanks to client-side validation, a feature in modern web browsers. This checks and displays errors as the form is filled out, ensuring inputs meet specific criteria before submission. Native HTML validation is useful because it enforces rules and guides users on what’s expected. However, if not well-designed, in-line error messages can become overwhelming. For example, flagging a field as incorrect after just one character can be disruptive, especially if the person filling out the form hasn't finished typing.

Email field with an inline error message that appears as soon as some character are typed
Premature error messages appearing before the full email address is entered can be disorientating

The ideal implementation of in-line messages is to appear once focus has moved to the next form field. When an error is detected, the message typically appears "in-line" or adjacent to the field in error. This approach provides immediate feedback without prematurely registering an error, and saves people from the frustration of submitting a form with errors. It also reduces cognitive load, making the form-filling process smoother and less stressful.

For example, password fields often have length requirements that should be clearly communicated both visually and programmatically for the benefit of people browsing with a screen reader. By using attributes like minlength and maxlength, you can easily control the number of characters allowed in a text field. If someone uses too few characters, in-line validation can immediately alert them to the error.

New password input field with three asterisks indicating entered characters. Below the field is a red error message that reads, ‘Error: Your password must contain at least 8 characters.
An inline error message appears after focus leaves the password field, indicating that the entered password is too short.

Post-submission error message

When a form is submitted, server-side validation checks for errors. If the form contains errors, they should ideally be reported in a summary at the top of the page. This approach has the advantage of not interrupting the flow of anyone filling out the form, ensuring that only valid data is submitted. However, this method can be frustrating if multiple errors are found, as it can be time-consuming to correct them all. Additionally, addressing numerous errors at once can increase cognitive load, making the process of fixing mistakes more challenging.

The default approach is to use a combination of both. Client-side validation provides quick feedback with inline error messages. Server-side validation catches errors missed or bypassed on the client side and can report error summaries clearly and concisely. Using both creates a balanced and reliable validation system.

Error summary box with two bullet points in red text: ‘The name field is required’ and ‘Your password must contain at least 8 characters.
This error summary appears at the top of a form, listing issues that need to be addressed by the user before submission.

Common accessibility issues with form validation and error messages

Most common issues with form validation and error messages can be easily avoided. It is common to see, but easy to solve, with the following techniques.

The error state of the form is not communicated

When a form field with an error state gets focus, it doesn't always communicate the error to assistive technologies, leaving screen reader users unaware of the issue and failing to meet accessibility standard 4.1.2 Name, role, value.

The solution is to add the aria-invalid="true" attribute to the field with an error. This ensures assistive technologies can recognise and announce the error when the field is focused.

The error messages are not communicated to assistive technology

Sometimes, error messages are visible on the screen but not communicated to assistive technologies, preventing screen reader users from receiving important information, making it difficult for people with visual impairments to correct mistakes and complete the form accurately. This can also lead to a failure to meet 4.1.3 Status messages.

The solution is to ensure they are announced by adding role="alert" to error elements. Alternatively, use aria-live regions to ensure changes to error messages are promptly communicated. For more guidance on how to implement live region, see Why are my live regions not working?.

Error messages are not associated with the field in error

Sometimes, error messages appear visually connected to a field, but the markup doesn't support that relationship. As a result, screen readers don't recognise the error message as related to the field, making it harder for users with visual impairments to fix errors. It can also lead to a 1.3.1 Info and relationships failure.

The solution is to use the aria-describedby attribute on the control and set it to the id of the element containing the error message so screen readers can link the message to the correct field. Ensure that the id/aria-describedby relationship is only active when an error is present, or include the error message text in the DOM only when an error occurs. Otherwise, if the error message text remains in the DOM when the control is not in an error state, it may still be announced, even if it is hidden.

Write clear and helpful error messages

After addressing the markup for accessible form validation, focus on making error messages clear and actionable. Error messages must contain helpful guidance for resolving errors. Simply notifying people of a problem isn’t enough; clear instructions on how to fix it are essential. This will also ensure that success criteria 3.3.3 Error suggestion is fulfilled.

  • Provide specific instructions: clearly describe what needs to be corrected. For example, if an email is entered incorrectly, explain what is missing or incorrect
  • Include examples or suggestions: whenever possible, offer examples or suggestions to guide people in fixing the error
  • Be concise and focused: ensure that error messages are brief and to the point; clear and concise messages help everyone quickly understand and resolve issues without confusion
Email input field populated with ‘dfeltham@tetralogicalcom’. Below the field is a red error message that reads, ‘Error: Enter in the format: name@example.com.’
Inline error messages with clear instructions help users understand the correct format for input, making the form easier to complete.

Tips

Tips for accessible form validation and error messages:

  • Combine in-line and post-submission validation: use a combination of in-line and post-submission error messages to provide comprehensive feedback
  • Expose error states: add the aria-invalid="true" attribute to communicate errors to assistive technologies
  • Ensure error messages are accessible: make sure screen readers can announce error messages by using appropriate attributes like role="alert" or aria-live
  • Associate error messages with fields: use the aria-describedby attribute to link error messages to the relevant form fields, ensuring accessibility for assistive technologies
  • Provide clear instructions: offer specific and actionable guidance on how to resolve errors

Next steps

Read more accessibility foundations posts or sign up for Accessibility Unlocked, our free six-day newsletter series designed to help you kick-start accessibility.