Accessibility in HTML
Accessible Forms and Inputs
Forms are one of the most interactive parts of a website, and as such, they should be designed to be usable by everyone effectively. In this chapter, we will learn the best practices for creating accessible forms, ensuring they are understandable and functional for all users, including those using assistive technologies.
Key Principles for Accessible Forms
- Associate labels with input fields: Correct use of labels (
<label>
) ensures that users can identify the purpose of each field. - Provide clear instructions: Instructions should be visible and understandable.
- Include descriptions and error messages: Help users fill out the form correctly.
- Simple navigation: Forms should be operable with a keyboard and have a logical order.
Correct Use of <label>
Each input field should be associated with a label using the for
attribute. This allows screen readers to identify the purpose of the field.
Basic example:
html
Use of Accessibility Attributes
Attributes like aria-describedby
and aria-invalid
can complement labels to provide additional information.
Example with descriptions and validation:
html
Accessible Error Messages
Error messages should be visible, clear, and accessible via assistive technologies.
Example with error messages:
html
Keyboard Navigation
Ensure users can easily navigate the form using only the keyboard. The tabindex
attribute can help control the order of elements.
Example of navigation order:
html
Accessible Validation
Validation should be clear and allow users to understand the errors without confusion. Use both native HTML validation and additional accessible validation.
Example of native validation:
html
Conclusion
Creating accessible forms not only improves usability for people with disabilities but also benefits all users by making forms clearer and more functional. Applying labels, descriptive attributes, and appropriate validation are essential steps.
In the next chapter, we will explore how to make images, videos, and graphics accessible using alternative text, captions, and other techniques. See you there!
- Introduction to Accessibility in HTML
- Web Content Accessibility Guidelines (WCAG)
- Semantic HTML for Accessibility
- Accessible Forms and Inputs
- Accessible Images, Media, and Graphics
- Accessible Navigation and Focus Management
- ARIA: Accessible Rich Internet Applications
- Accessibility in Custom Components
- Evaluación y Pruebas de Accesibilidad
- Relationship Between Performance and Accessibility
- Creating an Accessible Workflow
- Course Conclusion: Accessibility in HTML