Tooltip and hint
Two small bubbles in the page's colours turned round. A tooltip says a little more about whatever the pointer or the keyboard is on. A hint points at a control someone may have missed, once.
Tooltip
Show code
<!-- An icon button: the bubble says its label -->
<button type="button" class="btn-secondary" aria-label="Copy the link" data-tip>…</button>
<!-- A mark in a chart: its own words, a new line for each \n -->
<li tabindex="0" data-tip="Sunday 15 November\n143 page views\n68 visits">…</li>
<script>
import { tooltips } from '@somnia/core/lib/tooltip.js';
tooltips(document.querySelector('.chart')); // marks: at once
tooltips(document.querySelector('.toolbar'), { delay: 400 }); // buttons: after a rest
</script> - One bubble for a whole area:
tooltips(root)shows the words of whatever inside it carriesdata-tip. An emptydata-tipshows the control's own label (aria-label). - The same words on hover, on touch and on keyboard focus.
- Placed by itself: centred over the mark with an arrow to it, under it when there's no room above, and never off the edge of the screen.
- Two or three short lines at most. With more than one line the first is the title.
- A wait for buttons (
delay: 400), so crossing a toolbar doesn't flash every label. None for marks in a chart, where the reader is moving along them.
Hint: the help bubble
Show code
<div class="sn-hint" hidden>
<p>Tap here for the site’s sections and settings</p>
<button type="button" class="sn-hint-x" aria-label="Dismiss">…</button>
</div>
<script>
import { hint } from '@somnia/core/lib/tooltip.js';
hint(document.querySelector('.sn-hint'), { stay: 6000 });
</script> - For a control people have been missing, found by watching them miss it. Somnia CMS uses one: on a phone its sections are behind a bar at the top, which people missed.
- Once, then never again. Shown once a visit until the control has been used on that device, and not after. Deciding that is the page's job;
hint(box, { stay })handles the rest. - It goes by itself after a few seconds, at its close button, or at the first touch anywhere else. It never blocks the page.
- An arrow at the control: above the bubble near its end by default.
data-arrow="start","below"or"below start"move it, and--sn-hint-arrowsets how far in it sits. - One at a time, and one sentence.
Which bubble, or neither?
| The words are | Use |
|---|---|
| Needed to fill in a field | A hint under the field (form field): always there, never hidden |
| The name of an icon button, or the exact figure for a mark | A tooltip |
| About a control someone hasn't found | A hint, once |
| About what just happened | A toast |
| Something the reader must not miss | A notice in the page |
Do and don't
Do
- Keep a tooltip to what a glance can take in
- Give every icon-only button a label, then a tooltip of it
Don't
- Put instructions someone needs in a tooltip
- Show a hint on every visit, or two at once
Accessibility
What it does for you
- One bubble for hover, touch and keyboard focus, with the same words each way.
- Escape puts it away without moving the pointer or the focus; the pointer can move onto it; it stays until the pointer or focus leaves.
role="tooltip", and it never takes the focus or holds anything to press.- Placed on the screen, never off its edge, and put away when the page scrolls under it.
- The hint has a real close button with a name, and goes by itself.
- No motion beyond a fade with reduced motion. Neither is printed.
What you need to do
- Put the words somewhere a tooltip isn’t needed too: in the mark’s text (hidden text is fine) or its
aria-label. A tooltip is not read out reliably. - Give a mark that isn’t a control
tabindex="0", or it can’t be reached with Tab. - Give every icon-only button an
aria-label; an emptydata-tipthen shows it. - Decide when a hint is offered, and stop offering it once the control has been used.
Keyboard
| Key | What it does |
|---|---|
| Tab | Moves to a mark or button; its bubble shows. Moving on shows the next one’s instead. |
| Escape | Puts the bubble away. The focus stays where it was. |
| Tab (hint) | Reaches the hint’s close button. |
| Enter or Space (hint) | Closes the hint. |
What a screen reader is told
- The mark’s own words, from its text or label: "Tuesday 10 November: 114 page views, 52 visits".
- The bubble: role tooltip. It adds nothing a screen reader needs, and may not be read at all.
- The hint’s close button: a button named "Dismiss".
This is what the browser reports to assistive technology. What each screen reader then says varies, and has not been listened to yet.
WCAG 2.2
| Criterion | Level | How this meets it |
|---|---|---|
| 1.4.13 Content on Hover or Focus | AA | Dismissible (Escape), hoverable (the pointer can move onto it) and persistent (it stays until the pointer or focus leaves). |
| 2.1.1 Keyboard | A | Everything a pointer can show, keyboard focus shows. |
| 2.2.1 Timing Adjustable | A | The hint goes after a few seconds, but nothing is only in it: the control it points at is still there. |
| 4.1.2 Name, Role, Value | A | Marks are named by their text or label; the hint’s close button is a named button. |
The criteria this component has a part in. A page that uses it still has to meet the rest.
Checked
| Check | How | Result |
|---|---|---|
| Automated (axe-core) | WCAG 2.0, 2.1 and 2.2 rules at A and AA, the page in light and in dark | Passed Nothing found, light or dark |
| Narrow screen | No sideways scrolling at 320px wide (WCAG 1.4.10) | Passed No sideways scrolling |
| Keyboard and what the browser reports | Real key presses on the live example, and the role, name and state given to assistive technology | Passed 8 of 8 checks pass |
| On paper | Somnia’s print check: no overlaps, stranded headings or controls on the page | Passed No faults on 6 sheets |
| Screen reader | Listened to by a person, in VoiceOver and NVDA | Not yet Not yet checked by a person |
The 8 checks made with the keyboard, on the example at the top of this page:
- Passed Tab to a mark shows its bubble, with the mark’s own words
- Passed Escape puts the bubble away and the focus stays where it was
- Passed Moving on with Tab shows the next mark’s words instead
- Passed Leaving the marks puts it away
- Passed An icon-only button is named by its label, and its bubble says the same words
- Passed The bubble is a tooltip to the browser, and never takes the focus
- Passed Every bar’s figures are also in the page as text, without the bubble
- Passed The hint’s close button is reached by Tab, is named, and Enter closes the hint
Run by script on against Somnia DS 1.89.0, in Chromium with axe-core 4.14.0. How these checks work, and every component's results.
Not yet checked
- How it sounds in a screen reader (VoiceOver, NVDA, TalkBack) has not been checked by a person. The roles, names and states the browser reports are checked by script; what is actually spoken is not.
- The bubble is not tied to its mark with
aria-describedby, by design (the words are already in the mark’s name). Whether that suits screen reader users has not been checked with them. - On a touch screen the bubble shows on a tap; whether people find that has not been watched.
Evidence
Where it's used
| Where | For |
|---|---|
| Somnia CMS, Visitors | The exact figure for every column, bar, map country and hour. |
| Somnia CMS on a phone | A hint at the bar that holds the site’s sections and settings. |
What we saw, and what changed
| When | What we saw | What changed |
|---|---|---|
| On a phone, Somnia CMS’s sections and settings sit behind a bar at the top, which people missed. | A hint points at it, once a visit, until the menu has been used on that device. | |
| The bar’s caret glows as a reminder after the hint has gone. Shown every visit, it would wave at someone who uses the CMS daily for ever. | The glow stops after five visits. | |
| The hint was a card like the cards it sat over, and got lost among them. | Its colours were turned round: ink behind, the page colour for the words. | |
| The Visitors page needed the exact figure for every bar, country and hour, by mouse, touch and keyboard alike. | One bubble for all three, which became this component (1.77.0). | |
axe found the bubble inside a list of bars: a div where only list items may go. | The bubble is added to the nearest element that may hold one. |
From building and using it on real sites, each entry taken from the changelog or the build's own notes. This is observation by the studio and its clients, not research sessions with users.
What it rests on
- WCAG 2.2: Content on Hover or Focus: Dismissible, hoverable, persistent.
- ARIA Authoring Practices: Tooltip: Shown on focus as well as hover; Escape dismisses; the tooltip never takes the focus.
- Nielsen Norman Group: Tooltip Guidelines: Never put what someone needs to finish a task in a tooltip.
What we don't know yet
- We don’t know how many people still miss the bar: nothing counts it.