Implementing Logical Tab Order

Tutorial 2 of 5

Implementing Logical Tab Order

1. Introduction

This tutorial aims to guide you through the process of implementing a logical tab order on your web pages. A logical tab order helps to control the sequence in which elements receive focus when the user navigates using the 'Tab' key. It's a key aspect of accessibility, ensuring your website is usable for everyone, including those with disabilities.

You will learn:
* The concept of tab order
* How to use the HTML tabindex attribute to control tab order
* The importance of logical tab order

Prerequisites:
* Basic understanding of HTML and CSS
* A text editor (like Sublime Text, Notepad++, Atom, etc.)
* A modern web browser

2. Step-by-Step Guide

Tab order is determined by the order in which elements appear in the HTML source code. By default, the tab order is the same as the order of elements in the HTML. However, we can manipulate this order using the "tabindex" attribute.

The tabindex attribute can have three types of values:
* Positive values (1, 2, 3, etc.): The element will be placed in the specified tab order.
* 0: The element will be placed in the default tab order defined by the HTML structure.
* Negative values (-1): The element will be removed from the tab order.

Best Practices:
* Avoid using positive tabindex values. It can lead to a confusing tab order.
* Use tabindex="0" to include elements that are not focusable by default.
* Use tabindex="-1" to make elements unfocusable, if necessary.

3. Code Examples

Example 1: Default Tab Order

<!-- HTML -->
<div>First Div</div>
<button>First Button</button>
<a href="#">First Link</a>

In this case, tabbing will navigate from the div to the button, then to the link, following the HTML structure.

Example 2: Using Tabindex

<!-- HTML -->
<div tabindex="0">First Div</div>
<button>First Button</button>
<a href="#" tabindex="-1">First Link</a>

Here, the div is now focusable, and the link is removed from the tab order. So, tabbing will navigate from the div to the button.

4. Summary

This tutorial covered the topic of implementing a logical tab order on your web pages. We discussed the concept of tab order, the use of the tabindex attribute, and some best practices. The next steps would include practicing and experimenting with tab orders on your own web pages.

For additional resources, you might want to check out the Web Accessibility Initiative on the W3C's website.

5. Practice Exercises

Exercise 1: Create a simple HTML page with several elements and experiment with the tab order using the tabindex attribute.

Exercise 2: Take an existing HTML page and try to improve its accessibility by implementing a logical tab order.

Tips for further practice: Experiment with different HTML elements and see how they behave by default in the tab order. Try to understand why certain elements are focusable by default and others are not.