LEARNING OBJECTIVES โต
- Understand why native HTML
titleattributes fail modern accessibility benchmarks. - Implement the WAI-ARIA Tooltip Pattern using
role="tooltip"andaria-describedby. - Comply with all three mandates of WCAG 2.2 Success Criterion 1.4.13 (Dismissible, Hoverable, Persistent).
- Build responsive CSS and JavaScript triggers that synchronize mouse hover, keyboard focus, and
Escapekey dismissal.
๐ The Mental Model & Story (Intuitive Foundation)
Imagine walking through an art museum inspecting ancient artifacts. Beside a display case is an obscure bronze dial. As you lean in to look closely, a museum docent quietly whispers in your ear: "That dial was used by Greek sailors to calculate lunar eclipses."
If you lean back, the docent stops talking. If you find the explanation distracting, you can politely hold up your hand, and the docent steps back immediately.
Visual Pointer User:
[Hover over Icon Button] โโโ> [Tooltip bubble pops up] โโโ> [Hover over bubble to read]
Keyboard User:
[Tab onto Icon Button] โโโ> [Tooltip appears & is spoken] โโโ> [Press Escape to dismiss]
In web interfaces, a Tooltip is that quiet docent. It provides non-essential supplementary context to an interactive control without cluttering the main visual layout.
However, when tooltips are coded poorly, they become nightmares:
- They disappear when you try to hover over them to zoom in.
- They pop up on screen and permanently obscure the text underneath.
- They never appear for keyboard users.
- They are completely invisible to screen readers because they rely on fragile CSS
:hoverhacks.
Technical Deep Dive & Specifications
Why the Native title Attribute is Obsolete
For decades, developers relied on <button title="Print Document">. However, the native title attribute suffers from fatal accessibility defects:
| Problem | Native title Attribute |
Accessible ARIA Tooltip |
|---|---|---|
| Keyboard Accessibility | โ Never triggers on keyboard focus in most browsers | โ
Triggers immediately on :focus and :focus-visible |
| Touchscreen Devices | โ No touch trigger support on mobile iOS/Android | โ Can be toggled on long-press or tap |
| WCAG 1.4.13 Compliance | โ Cannot be dismissed via Escape, not hoverable |
โ Fully dismissible, hoverable, and persistent |
| Visual Styling | โ Hardcoded by OS window manager, microscopic font | โ Fully styleable with CSS Custom Properties and animations |
| Screen Magnifiers | โ Disappears if user moves magnifier cursor over text | โ User can move mouse over tooltip content safely |
The WAI-ARIA Tooltip Architecture
+-------------------------------------------------------------------------------+
| TRIGGER ELEMENT: |
| <button aria-describedby="tip-save" aria-label="Save File"> |
| <svg aria-hidden="true">...</svg> |
| </button> |
+-------------------------------------------------------------------------------+
โ
aria-describedby
โ
โผ
+-------------------------------------------------------------------------------+
| TOOLTIP CONTAINER: |
| <div id="tip-save" role="tooltip" class="tooltip-bubble"> |
| Saves your changes to cloud storage (Ctrl+S) |
| </div> |
+-------------------------------------------------------------------------------+
aria-describedbyRelationship: Connects the interactive trigger to the tooltip<div>. Screen readers announce:"Save File, button. Saves your changes to cloud storage (Ctrl+S)."
role="tooltip": Identifies the element as a temporary supplementary bubble in the Accessibility Tree.- No Interactive Children: A tooltip must never contain links, inputs, or buttons. If content requires user interaction, it is a Popover or Dialog, not a tooltip.
WCAG 2.2 Success Criterion 1.4.13: Content on Hover or Focus
To meet Level AA compliance, every tooltip must satisfy the D.H.P. Rule:
+โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ+
| WCAG 1.4.13 THREE CORE CRITERIA |
+โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ+
| 1. DISMISSIBLE | Pressing [Escape] or triggering an action closes the |
| | tooltip without moving pointer hover or keyboard focus. |
|โโโโโโโโโโโโโโโโโโโ|โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ|
| 2. HOVERABLE | Pointer can move from the trigger onto the tooltip |
| | container itself without the tooltip closing. |
|โโโโโโโโโโโโโโโโโโโ|โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ|
| 3. PERSISTENT | Tooltip remains visible until hover/focus is removed or |
| | explicitly dismissed by the user. |
+โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ+
๐ป Interactive Code Playground
Starter Code
Line-by-Line Code Breakdown
- Line 87 (
aria-describedby="tooltip-bookmark"): Associates the button with the tooltip message in the browser's accessibility graph. - Line 96 (
role="tooltip"): Declares the semantic role of the floating text bubble. - Line 66โ71 (
.tooltip-wrapper:hover .tooltip-box, .tooltip-box.is-visible): Enables the Hoverable rule. If a low-vision user moves their mouse from the button into the tooltip box to read it under screen magnification,pointer-events: autoensures the tooltip does not collapse. - Line 106โ110 (
if (e.key === 'Escape')): Satisfies the Dismissible rule, allowing users to close the overlay withEscapewithout losing focus.
Expected Browser Render Output
- Sighted Display: Hovering over the bookmark icon displays a crisp slate tooltip saying "Save this article to your reading list".
- Screen Reader Vocalization:
"Bookmark, button. Save this article to your reading list."
๐๏ธ Hands-On Exercise
๐ฏ The Challenge: Accessible Markdown Toolbar Tooltips
Build an accessible formatting toolbar containing three icon buttons: Bold, Italic, and Insert Code.
Instructions:
- Create three
<button class="toolbar-btn">elements. - Mark each button with an
aria-label(e.g.aria-label="Bold text") and anaria-describedbypointing to its keyboard shortcut tooltip (e.g.,Ctrl+B). - Markup the corresponding
<div role="tooltip">containers. - Support keyboard focus, mouse hover, and
Escapekey dismissal across all three tooltips.
๐ Starter Code Sandbox
โ ๏ธ Common Pitfalls
- Placing Interactive Content inside a Tooltip: Putting links, checkboxes, or buttons inside
role="tooltip"violates WAI-ARIA authoring practices. Use a Popover or Dialog widget instead. - Using
aria-labelinstead ofaria-describedbyon the Trigger: Overwritingaria-labelreplaces the button's accessible name rather than appending supplementary guidance. - Disappearing on Hover Over Bubble: If the tooltip vanishes the moment the pointer moves off the trigger and onto the tooltip text, you fail WCAG 1.4.13 (Hoverable).
- No Keyboard Dismissal: Failing to dismiss active tooltips on
Escapetraps screen magnifier users beneath the floating box.
๐ก Pro Tips
- Explore the Baseline Popover API: Modern browsers support
popover="hint"andinteresttargetfor declarative native tooltips. - Positioning Engines (Floating UI): For dynamic viewport boundaries (preventing tooltips from clipping off the top or right edges of the screen), use
@floating-ui/dom. - Touch Device Strategy: Tooltips generally do not apply to touch screens. Ensure essential information is displayed as permanent text or opened in a modal on tap.
๐ Key Takeaways
- Native HTML
titleattributes fail multiple WCAG standards and should be avoided for primary UI microcopy. - Always link tooltips using
aria-describedby="[tooltip-id]"paired withrole="tooltip". - WCAG 1.4.13 requires tooltips to be Dismissible (
Escape), Hoverable (pointer can hover over bubble), and Persistent (stays until dismissed). - Tooltips must only contain static, non-interactive text strings.
- --