Preview brand Custom

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.

Beta

Tooltip

  1. Tuesday 10 November: 114 page views, 52 visits
  2. Wednesday 11 November: 82 page views, 40 visits
  3. Thursday 12 November: 82 page views, 37 visits
  4. Friday 13 November: 68 page views, 33 visits
  5. Saturday 14 November: 131 page views, 61 visits
  6. Sunday 15 November: 143 page views, 68 visits
  7. Monday 16 November: 86 page views, 41 visits

  1. Tuesday 10 November: 114 page views, 52 visits
  2. Wednesday 11 November: 82 page views, 40 visits
  3. Thursday 12 November: 82 page views, 37 visits
  4. Friday 13 November: 68 page views, 33 visits
  5. Saturday 14 November: 131 page views, 61 visits
  6. Sunday 15 November: 143 page views, 68 visits
  7. Monday 16 November: 86 page views, 41 visits

Point at a bar or a button, touch it, or move to it with Tab. Escape puts the bubble away.
Show code
html
<!-- 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 carries data-tip. An empty data-tip shows 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

Visitors

Tap here for the site’s sections and settings

Visitors

Tap here for the site’s sections and settings

Show code
html
<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-arrow sets how far in it sits.
  • One at a time, and one sentence.

Which bubble, or neither?

The words areUse
Needed to fill in a fieldA hint under the field (form field): always there, never hidden
The name of an icon button, or the exact figure for a markA tooltip
About a control someone hasn't foundA hint, once
About what just happenedA toast
Something the reader must not missA 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 empty data-tip then shows it.
  • Decide when a hint is offered, and stop offering it once the control has been used.

Keyboard

KeyWhat it does
TabMoves to a mark or button; its bubble shows. Moving on shows the next one’s instead.
EscapePuts 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

CriterionLevelHow this meets it
1.4.13 Content on Hover or FocusAADismissible (Escape), hoverable (the pointer can move onto it) and persistent (it stays until the pointer or focus leaves).
2.1.1 KeyboardAEverything a pointer can show, keyboard focus shows.
2.2.1 Timing AdjustableAThe 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, ValueAMarks 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

CheckHowResult
Automated (axe-core)WCAG 2.0, 2.1 and 2.2 rules at A and AA, the page in light and in darkPassed
Nothing found, light or dark
Narrow screenNo sideways scrolling at 320px wide (WCAG 1.4.10)Passed
No sideways scrolling
Keyboard and what the browser reportsReal key presses on the live example, and the role, name and state given to assistive technologyPassed
8 of 8 checks pass
On paperSomnia’s print check: no overlaps, stranded headings or controls on the pagePassed
No faults on 6 sheets
Screen readerListened to by a person, in VoiceOver and NVDANot 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

WhereFor
Somnia CMS, VisitorsThe exact figure for every column, bar, map country and hour.
Somnia CMS on a phoneA hint at the bar that holds the site’s sections and settings.

What we saw, and what changed

WhenWhat we sawWhat 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

What we don't know yet

  • We don’t know how many people still miss the bar: nothing counts it.