- Lab
- Core Tech

Guided: Keyboard Navigation and Form Design for Web Accessibility
Enhance your web development skills in this Guided Code Lab focused on keyboard navigation and form design for web accessibility. Explore the essential principles of creating inclusive forms that cater to as many users as possible. Through hands-on tasks, you'll learn practical techniques to improve keyboard navigation, form labeling, and error message presentation. By the end of this lab, you'll be equipped to design user-friendly forms that adhere to accessibility guidelines, ensuring a seamless experience for everyone.

Path Info
Table of Contents
-
Challenge
Introduction
Keyboard navigation and accessible form design are crucial for web accessibility, enabling individuals with disabilities, such as motor or visual impairments, and those using assistive technologies, to interact effectively with web content. Adopting these practices ensures inclusive and user-friendly digital experiences for as many users as possible.
Scenario:
You have been assigned to implement accessibility improvements on a New User Registration Form for ABC-mobile. The form includes the following fields:
- First Name
- Last Name
- Area Code and Cell Phone Number
- User ID
- Password
In this lab, your objective is to apply web accessibility standards to the New User Registration Form on the ABC-mobile e-commerce site. ABC-mobile, a seller of phone accessories, requires new customers to register by providing specific information. Your task is to ensure that the form is accessible to users, including those who rely on keyboard navigation and screen readers.
A pre-built version of the form is provided as a starter file in the lab solution. Your role is to enhance the form's accessibility, ensuring it is fully keyboard-operable and accessible for users.
By completing this lab, you will be able to:
-
Implement Character Key Shortcuts:
Set up keyboard shortcuts for more efficient navigation. -
Improve Keyboard Focus & Visibility:
Ensure all interactive elements are keyboard-accessible and visually distinct when focused. -
Associate Labels with Form Controls:
Correctly link labels with form controls for better screen reader support. -
Add Contextual Information to Form Elements:
Associate additional information, enhancing accessibility for users relying on screen readers. -
Implement Accessible Error Messages:
Present error messages in a way that is accessible for form validation.
Before you start, here are some important points to note:
-
Your primary task will involve coding in the
index.html
file, along with making some modifications in thescript.js
andstyles.css
files. -
If you face any difficulties, don’t hesitate to refer to the
solution
directory. -
After making code changes, refresh the browser to see the updates take effect.
-
To check for accessibility features, you will need a screen reader, which can be activated using the following keys:
- Windows:
Windows + Control + Enter
- Linux:
Alternate + Windows + S
( Orca Screen reader ) - Mac:
Command + F5
- Windows:
-
Challenge
Implement Character Key Shortcuts
In this step, you will implement character key shortcuts, which users will use to quickly navigate to specific field in the form.
This can be achieved by adding an
accesskey
attribute to theinput
tag.In the below example,
accesskey=q
is added to theinput
tag.Example:
<input type="text" id="first-name" name="first-name" accesskey="q" required>
You can use the keyboard to navigate the form by pressing
Alternate + [Key]
on Windows and Linux orControl + [Key]
on macOS to move focus to the respective fields.info> Ensure that you don't assign an
accesskey
that conflicts with existing browser shortcuts.In this step, you learned how to add keyboard shortcuts to help users quickly access specific form fields, enhancing both usability and accessibility. As users navigate to each input field, the screen reader announces the assigned shortcut key.
In the next step, you'll dive into how to improve keyboard focus & visibility. You'll learn how to make all interactive elements fully accessible via keyboard and clearly visible when focused, which is essential for users relying on keyboard navigation to interact with your form effectively.
-
Challenge
Enhance Keyboard Focus & Visibility
Designing webpages for users with motor and visual impairments involves making websites fully accessible through keyboard navigation, providing clear focus indicators, and minimizing the need for fine motor control (e.g., precise clicks). For users with visual impairments, clear and visible focus indicators are essential, helping them track their location on a page as they navigate forms or other interactive elements.
In this step, you'll ensure that all interactive components, including input fields and buttons, are both keyboard-accessible and visually prominent when focused. This is critical for users relying on keyboard navigation to interact effectively with the form.
In this step, you'll work on:
- Using the
tabindex
attribute to establish a logical and intuitive navigation order. - Applying clear
CSS
outlines or background changes to enhance the visibility of focused elements.
The
tabindex
Attributetabindex
is an HTML attribute that controls the order in which elements on a webpage are focused when navigating using the keyboard, specifically theTab
key. It helps improve accessibility by determining the sequence in which users move through interactive elements like form fields, buttons, and links.Example:
<input type="text" name="name" tabindex="1"> <input type="text" name="email" tabindex="2">
You'll now add the
tabindex
attribute to all of theinput
fields and the Register button. In this step, you ensured that all form elements are keyboard-accessible by using thetabindex
attribute and applied clear visual indicators for focused elements.Next, you'll focus on associating form controls with labels to improve screen reader accessibility.
- Using the
-
Challenge
Associate Labels with Form Controls
In this step, you'll focus on ensuring that all labels are properly associated with their corresponding form controls. This is essential for accessibility, as it helps screen readers provide users with the context they need when interacting with form fields.
You have to ensure that each form control is clearly linked to its label using the
for
attribute. This will make the form more accessible for users relying on screen readers and improve overall usability.Example :
<div class="form-group"> <label for="ageField" >Age (Number)</label> <input type="text" id="ageField" name="first-name" required> </div>
In this example, the
for="ageField"
attribute in the label links it to theid="ageField"
of the input field. When a user navigates to the input field, screen readers will announce the label text, "Age (Number)". This association helps users understand the purpose of the input field and provides context for the data they need to enter.info> The screen reader announces "Age (Number)" when you navigate to the input box, as it's associated with the linked label.
Now, you will update your registration form with these details. Linking a label helps users understand the current text box, but what if you need to provide additional information without enlarging the visible label?
In such cases, you can use
aria-label
to provide extra details, which the screen reader will announce when the text box is selected.Example :
<label>Date of Birth</label> <input type="date" id="dob" name="dob" aria-label="Date of Birth. Use the format MM/DD/YYYY" required>
info> In this example, the screen reader will announce: "Date of Birth. Use the format MM/DD/YYYY,"
The visible label remains as "Date of Birth", but this allows you to provide more context without cluttering the interface.
You will now add an
aria-label
to the Phone Number field. Great job! These updates have enhanced the form’s accessibility, making it easier for users relying on assistive technologies to navigate and understand the form fields.In the next step, you’ll learn how to further improve accessibility by using the
aria-labelledby
attribute to associate form elements with multiple labels or descriptions, providing even more context for screen readers. -
Challenge
Enhance Form Elements with Contextual Information
In this step, you will learn how to associate form elements with additional contextual information, making them even more accessible and user-friendly for individuals relying on screen readers.
Some form fields require more than just a simple label. They may need additional information to ensure users fully understand what is required.
For example, a form has a "User ID" label, but the user may also need to know that the User ID should be between 4-16 characters.
You can provide a brief message below the text box to convey this information. Additionally, to ensure that assistive technologies announce this message, you'll associate the input with the message
aria-labelledby
.
Now, you'll update the User ID field to have additional information.
Great! When you navigate to the User ID field, the narrator will announce "User ID should be 8-12 characters, letters, and numbers only".
Next, you'll explore how to ensure error messages are accessible to all users.
-
Challenge
Present Error Messages
In this step, you will enhance the form's error handling by implementing accessible error messages. These messages provide users with feedback when required fields are not filled in or when the input is invalid.
You'll utilize ARIA attributes, such as
aria-live
andaria-invalid
, to ensure that screen readers properly announce these error messages.
The
aria-invalid
AttributeThe
aria-invalid
attribute is used to mark an input field as invalid when the user enters incorrect or missing information. It provides feedback to screen reader users that a particular field has failed validation, ensuring they are aware of the issue.
The
aria-live
AttributeThe
aria-live
attribute allows content such as error messages to be announced automatically by screen readers without the user needing to focus on it.It can be set to different values, such as:
aria-live="polite"
: Announcements are made when the user is idle, so it does not interrupt the user’s current task.aria-live="assertive"
: Announcements are made immediately, interrupting the user to ensure they are aware of the issue.
This is useful for alerting users of validation errors in real-time.
Using
aria-invalid
andaria-live
Attributes TogetherCombining
aria-invalid
andaria-live
makes form validation more accessible.aria-invalid
marks a field as invalid, whilearia-live
ensures error messages are automatically announced.How It Works:
- Invalid Input:
aria-invalid="true"
tells the screen reader that the field is in an invalid state. - Error Announcement: The error message with
aria-live="assertive"
is read aloud when it appears or changes.
Now, you will apply the
aria-invalid=false
attribute to all of the form input fields. Great! Now all of the fields are valid at the start.Next, update the error field to include the
aria-live
attribute, ensuring that any new errors added are announced by the screen reader. Next, you will verify whether the fields are not empty. If any field is blank, you will mark it as invalid by settingaria-invalid
totrue
. You will implement these changes in thescript.js
file.The
script.js
file loops through all input fields and checks if their values are blank. You can test the form by leaving one field empty. An error message in red should appear at the bottom, and the screen reader will announce the relevant error.
Great job! With these changes, error messages are now announced to users, making it easier for them to understand the issue.
You can use the screen reader to test the webpage by entering data and submitting the form.
-
Challenge
Conclusion & Next Steps
In this lab, you have learned how to make your web forms more accessible by implementing key accessibility features, such as character key shortcuts, keyboard focus & visibility, form labels, and accessible error message presentation using ARIA attributes.
These techniques are essential for creating an inclusive user experience, especially for individuals who rely on assistive technologies.
Next Steps:
- Explore additional ARIA attributes and their appropriate use cases.
- Continue practicing these concepts by applying them to more complex forms or other interactive elements on your website.
- Consider testing your forms using screen readers to experience firsthand how accessible they are to users with disabilities.
By integrating these accessibility practices into your development workflow, you’ll ensure that your websites are usable and inclusive for all.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.