In this tutorial, we are going to ensure our web interfaces are keyboard accessible. This is crucial because not everyone uses a mouse or touchscreen to interact with websites. Some people rely on their keyboards, so we should design our web interfaces accordingly to provide a great user experience for all users.
By the end of this tutorial, you will learn how to:
Prerequisites:
The tabindex
attribute specifies the tab order of an element. By default, the tab order is defined by the order in which elements appear in the HTML. However, you can use the tabindex
attribute to change this.
Best practices:
tabindex
greater than 0. This can disrupt the natural tab order of the browser.tabindex="-1"
to make an element focusable, but not reachable via sequential keyboard navigation.Accessible Rich Internet Applications (ARIA) is a set of attributes that define ways to make web content and web applications more accessible to people with disabilities. They can be added to HTML elements to provide additional semantics and improve accessibility.
Best practices:
<!-- This element will be focusable, but not reachable via sequential keyboard navigation -->
<div tabindex="-1"></div>
<!-- This element will be recognized by screen readers as a navigation bar -->
<nav aria-label="Main navigation"></nav>
In this tutorial, we learned how to evaluate and improve the keyboard accessibility of our web interfaces by understanding the tabindex
attribute and implementing ARIA roles.
Next steps for learning:
Additional resources:
tabindex
attributes to your page and see how it changes the tab order.Solutions
tabindex
of "-1" to an element, it becomes focusable but not reachable through sequential keyboard navigation.<nav aria-label="Main navigation"></nav>
. Test it with a screen reader to notice the difference.Tips for further practice