HTML Concepts: Focusable Areas
Published on May 30, 2022 (↻ December 24, 2023), filed under Development (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.)
Focusable Areas
According to the spec, what can be focusable areas?
- Elements whose
tabindex
value is not null, which are neither a shadow host or have a shadow root whose delegates focus is false, are not disabled or inert, and that are either being rendered, or used as canvas fallback content. - The shapes of
area
elements in image maps that are associated withimg
elements that are being rendered (and not inert). - The sub-widgets of elements that are being rendered and that are not disabled or inert (for example, video controls).
- The scrollable regions of elements that are being rendered (and not inert).
- The viewports of
Document
s with a browsing context that is not null (and not inert). - Any other element or part thereof that is determined by the user agent to be a focusable area (for example, to help accessibility).
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 aNode
, 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!
About Me
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.)
Read More
Maybe of interest to you, too:
- Next: The Machine-Illustrated Life of a Frontend Developer
- Previous: “The One With the Biggest Hammer Wins”
- More under Development
- More from 2022
- Most popular posts
Looking for a way to comment? Comments have been disabled, unfortunately.
Get a good look at web development? Try WebGlossary.info—and The Web Development Glossary 3K. With explanations and definitions for thousands of terms of web development, web design, and related fields, building on Wikipedia as well as MDN Web Docs. Available at Apple Books, Kobo, Google Play Books, and Leanpub.