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.
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):
| Markup | Role | Accessible name | Description |
|---|---|---|---|
<button data-tooltip> with the ::after bubble | button | "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:
| Step | CSS-only bubble |
|---|---|
| Hover the trigger | shown |
| Move the pointer onto the bubble | disappears (pointer-events: none, and the trigger loses :hover) |
| Press Escape while hovering | stays (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
- The
popoverattribute gives you top-layer display and Escape to close without writing the key handler. MDN's compatibility data lists it in Chrome and Edge 114, Firefox 125 and Safari 17. It is built for click-opened popups. popover="hint", the variant meant for hover and focus hints, works to the current specification only in Chrome and Edge 151 and Firefox 153 (both July 2026), with an older, inconsistent version before that and Safari still in preview. Not something to rely on alone yet.- CSS anchor positioning places the bubble next to its trigger and can flip it when it would leave the screen, with no JavaScript measuring. It shipped in Chrome 125, Firefox 147 and Safari 26, with current-specification behavior from Chrome 151, Firefox 151 and Safari 27 (September 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?
How do I add an arrow to a CSS tooltip?
Are CSS tooltips accessible?
Use the CSS Tooltip Generator โ free, no signup required.
โก Open CSS Tooltip Generator- [1]W3C, Understanding WCAG 2.2 SC 1.4.13 Content on Hover or Focus โ
- [2]W3C WAI-ARIA Authoring Practices, Tooltip pattern โ
- [3]W3C, Accessible Name and Description Computation 1.2 (CSS generated content) โ
- [4]MDN, title global attribute: accessibility concerns, checked Oct 13, 2026 โ
- [5]MDN browser-compat-data, html.global_attributes.popover (incl. hint), checked Oct 13, 2026 โ
- [6]MDN browser-compat-data, css.properties.position-anchor, checked Oct 13, 2026 โ