CSSMar 9, 2026 ยท Updated Oct 13, 2026 ยท 4 min read

How to Build an Accessible CSS Tooltip

The CSS-only tooltip, what screen readers actually get from it (we read Chromium's accessibility tree), why it fails WCAG 1.4.13, and a tested pattern that passes, plus the native popover and anchor positioning options in 2026.

๐Ÿ’ฌ
Try the CSS Tooltip Generator
Free, no signup
โ†’
DG
Derek Giordano
Designer & Developer
In this guide
01The Basic CSS Tooltip02What Screen Readers Get03WCAG 1.4.13: Hoverable, Dismissible, Persistent04A Pattern That Passes05Native Options in 2026

The Basic CSS Tooltip

The classic CSS-only tooltip stores the text in a data attribute and shows it with a pseudo-element:

[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 6px;
  background: #1a1a2e;
  color: #fff;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after { opacity: 1; }
<button type="button" data-tooltip="Copies the link">Share</button>

An arrow is a second pseudo-element (::before) with transparent borders on three sides and the bubble color on the side that points at the trigger. It looks finished. It is not, for two reasons we measured.

What Screen Readers Get

Screen readers read the browser's accessibility tree, not the CSS. We built four versions of the same "Share" button and read Chromium's accessibility tree back through the DevTools protocol (October 13, 2026):

MarkupRoleAccessible nameDescription
<button data-tooltip> with the ::after bubblebutton"Share Copies the link"none
<span tabindex="0" data-tooltip>generic""none
<button aria-describedby="tip"> + <span role="tooltip" id="tip">button"Share""Copies the link"
<button title>button"Share""Copies the link"

The pseudo-element text does not disappear for screen readers when it is invisible: CSS generated content counts toward an element's accessible name, so the button is announced as "Share Copies the link" on every visit, with the tooltip wording glued onto the label. Putting the tooltip on a span with tabindex="0", as older guides suggest, is worse: the span gets keyboard focus but no role and an empty name. Only a real element linked with aria-describedby produces what a tooltip should be, a short description read after the name. The title attribute gets the same result in the tree, but MDN advises against relying on it because browsers show it on mouse hover and not on keyboard focus or touch.

WCAG 1.4.13: Hoverable, Dismissible, Persistent

WCAG 2.2 success criterion 1.4.13 (level AA) covers anything that appears on hover or focus. It must stay visible while the pointer moves onto it (hoverable), be dismissible without moving the pointer or focus, normally with Escape (dismissible), and stay until the user moves away or dismisses it (persistent). The CSS-only bubble fails two of the three:

StepCSS-only bubble
Hover the triggershown
Move the pointer onto the bubbledisappears (pointer-events: none, and the trigger loses :hover)
Press Escape while hoveringstays (nothing listens for the key)

People who magnify the screen need the first fix: at high zoom the tooltip can cover what they are reading, and they move the pointer over it to read it. The Escape requirement is the part CSS cannot do on its own.

A Pattern That Passes

A real element for the text, aria-describedby to connect it, a transparent bridge so the pointer can cross the gap, and a few lines of JavaScript for Escape:

<span class="tt">
  <button type="button" aria-describedby="tip-share">Share</button>
  <span role="tooltip" id="tip-share" class="tt__bubble">Copies the link</span>
</span>
.tt { position: relative; display: inline-block; }
.tt__bubble { position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  padding: 6px 12px; border-radius: 6px; background: #1a1a2e; color: #fff; white-space: nowrap;
  visibility: hidden; opacity: 0; transition: opacity 0.15s; }
.tt__bubble::before { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 8px; } /* bridge the gap */
.tt:hover .tt__bubble, .tt:focus-within .tt__bubble { visibility: visible; opacity: 1; }
.tt.is-dismissed .tt__bubble { visibility: hidden; opacity: 0; }
document.addEventListener('keydown', (e) => {
  if (e.key !== 'Escape') return;
  document.querySelectorAll('.tt:hover, .tt:focus-within').forEach((t) => t.classList.add('is-dismissed'));
});
for (const type of ['pointerout', 'focusout']) {
  document.addEventListener(type, (e) => {
    const t = e.target.closest && e.target.closest('.tt');
    if (t && !t.contains(e.relatedTarget)) t.classList.remove('is-dismissed');
  });
}

We ran the same checks on exactly this code: the accessibility tree gives the button the name "Share" and the description "Copies the link", and the tooltip shows on hover, stays when the pointer moves onto it, hides on Escape, comes back on the next hover, shows on keyboard focus, and hides on Escape from the keyboard too. Keep tooltips for supplementary hints; information people need to complete a task belongs in visible text.

Our CSS Tooltip Generator writes this structure for all four positions, including the Escape script.

Native Options in 2026

Until popover="hint" is everywhere, the pattern above is the safe default, and anchor positioning can replace its position: absolute math where you need flipping.

Frequently Asked Questions

How do I create a tooltip in CSS without JavaScript?+
The visual part is pure CSS: a positioned element or ::after pseudo-element shown on :hover and :focus-visible. Two parts need more. WCAG 2.2 success criterion 1.4.13 requires that the tooltip can be dismissed, normally with Escape, which takes a few lines of JavaScript, and screen readers only treat the text as a description when it lives in a real element referenced by aria-describedby.
How do I add an arrow to a CSS tooltip?+
Use the ::before pseudo-element with transparent borders on three sides and a colored border on the side facing the tooltip body. This creates a CSS triangle that serves as the arrow.
Are CSS tooltips accessible?+
Not on their own. In Chromium's accessibility tree, text from an ::after tooltip on a button is added to the button's name ("Share Copies the link") even while it is invisible, and a span made focusable with tabindex gets no role and no name. The CSS-only bubble also disappears when the pointer moves onto it and ignores Escape, which fails WCAG 1.4.13. A real element with role="tooltip", linked with aria-describedby, plus an Escape handler, passes.
Try it yourself

Use the CSS Tooltip Generator โ€” free, no signup required.

โšก Open CSS Tooltip Generator
DG
Derek Giordano
Written by the creator of Ultimate Design Tools. BA in Business Marketing.