HTML Concepts: Focusable Areas

Published on May 30, 2022 (↻ December 24, 2023), filed under (RSS feed for all categories).

When you hear “focusable area,” what comes to your mind? Anchors and form elements that receive focus when being “tabbed through,” i.e., that are highlighted and that can be interacted with?

That’s not a bad description!—but also not a complete one.

As always, the HTML specification deserves having a closer look at. (The spec is dry and intimidating, but consider reading it, if you haven’t.)

A focusable area in the HTML specification’s section on focusable areas.

Figure: Focusable areas meta.

Focusable Areas

According to the spec, what can be focusable areas?

Quite generally speaking, elements that have a tabindex and that are being rendered are focusable areas.

As so much here depends on tabindex, what is that attribute about?

tabindex

Its purpose is exactly what we’re covered here—to manage focusable areas.

Quoting the spec, the tabindex attribute “allows authors to make an element and regions that have the element as its DOM anchor be focusable areas, allow or prevent them from being sequentially focusable, and determine their relative ordering for sequential focus navigation.”

If the value of tabindex is omitted, the user agent determines whether the respective element is focusable.

A negative value makes an element focusable (but click-focusable, and not sequentially focusable, a difference the HTML spec also explains).

A value of 0 makes the element focusable.

A positive value (integer) makes the respective element focusable, but also defines the tab order, in that higher tabindex values mean elements to be focused later.

DOM Anchors

Yet this is not it; an important detail around focusable areas relates to DOM anchors, which determine the position of the focusable area in the DOM:

Each focusable area has a DOM anchor, which is a Node object that represents the position of the focusable area in the DOM. (When the focusable area is itself a Node, it is its own DOM anchor.) The DOM anchor is used in some APIs as a substitute for the focusable area when there is no other DOM object to represent the focusable area.

The focusable areas above each come with a particular DOM anchor; usually, the element itself, but for image maps, the img element, and for sub-widgets, the element it was created for.

❧ Focusable areas—more complex than they sound like, still not as hard in hindsight. Check out other aspects of HTML in the HTML concepts series!

Was this useful or interesting? Share (toot) this post, become a one-time nano-sponsor, or support my work by learning with my ebooks.

About Me

Jens Oliver Meiert, on November 9, 2024.

I’m Jens (long: Jens Oliver Meiert), and I’m a frontend engineering leader and tech author/publisher. I’ve worked as a technical lead for companies like Google and as an engineering manager for companies like Miro, I’m a contributor to several web standards, and I write and review books for O’Reilly and Frontend Dogma.

I love trying things, not only in web development (and engineering management), but also in other areas like philosophy. Here on meiert.com I share some of my experiences and views. (Please be critical, interpret charitably, and give feedback.)