Chuck's Academy

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

  1. Associate labels with input fields: Correct use of labels (<label>) ensures that users can identify the purpose of each field.
  2. Provide clear instructions: Instructions should be visible and understandable.
  3. Include descriptions and error messages: Help users fill out the form correctly.
  4. 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
"In this example, each input field has an associated label using the for attribute, which makes it easier for users with assistive technologies to identify the purpose of each field."

Use of Accessibility Attributes

Attributes like aria-describedby and aria-invalid can complement labels to provide additional information.

Example with descriptions and validation:

html
"This code includes an aria-describedby attribute that links the password field to an additional description. This helps users understand the rules or restrictions applied to the field."

Accessible Error Messages

Error messages should be visible, clear, and accessible via assistive technologies.

Example with error messages:

html
"In this example, the aria-invalid attribute indicates that the field contains an error, while the associated error message is dynamically updated to inform the user."

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
"This example uses the tabindex attribute to establish a logical navigation order in the form, ensuring a smooth experience for keyboard users."

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
"Here, native HTML validation is used, such as min and max attributes, to ensure the input data is valid. This simplifies the experience for both developers and users."

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!


Ask me anything