HTML Concepts: Focusable Areas
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.)
So according to the spec, what can be focusable areas?
- Elements whose
tabindexvalue 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
areaelements in an image map that is associated with an
imgelement that is 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 viewport of a
Documentwith 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?
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.
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
Nodeobject 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!
I’m Jens, and I’m an engineering lead and author. I’ve worked as a technical lead for Google, I’m close to W3C and WHATWG, and I write and review books for O’Reilly. I love trying things, sometimes including philosophy, art, and adventure. Here on meiert.com I share some of my views and experiences.
If you have a question or suggestion about what I write, please leave a comment (if available) or a message. Thank you!
Maybe this is interesting to you, too:
- Next: The Machine-Illustrated Life of a Frontend Developer
- Previous: “The One with the Biggest Hammer Wins”
- More under Web Development, or from 2022
- Most popular posts
Looking for a way to comment? Comments have been disabled, unfortunately.
Get a good look at web development? Try The Web Development Glossary (2020). With explanations and definitions for literally thousands of terms from Web Development and related fields, building on Wikipedia as well as the MDN Web Docs. Available at Apple Books, Kobo, Google Play Books, and Leanpub.