Developer and Text Tools

Accessible CSS Tooltips: Hover, Focus, Escape and Arrows

How to build CSS tooltips that work with a keyboard and screen reader, when pure CSS is enough, and how to style the arrow, timing and animation.

Saizul Amin
Saizul Amin5 Nov 2026 · 4 min read
Accessible CSS Tooltips: Hover, Focus, Escape and Arrows

Tooltips are small, but they often carry the only explanation of an icon. A toolbar full of icons with tooltips that only open on mouse hover leaves keyboard users, screen reader users and phone users guessing. Building a tooltip that works for everyone takes a few lines more than the classic hover-only trick, and those lines are worth it.

What a tooltip is, and what it is not

A tooltip is a short text label that appears when someone points at or focuses an element and disappears when they move away. It describes the element. It is not a place for links, buttons or forms, because people cannot move into it to use them. If you need interactive content, use a disclosure button that opens a popover. If you need help text that stays open when clicked, that is a toggletip, a different pattern.

The accessible pattern

The pattern recommended by the W3C's ARIA Authoring Practices has three parts:

  1. A focusable trigger, usually a button, so keyboard users can reach it with Tab.
  2. A tooltip element with role="tooltip" and a unique id.
  3. aria-describedby on the trigger pointing to that id, so screen readers read the tooltip text after the button's name.

CSS shows the tooltip when the wrapper is hovered or contains focus, using :hover and :focus-within. Because the trigger is a button, tapping it on a phone gives it focus and the tooltip appears too.

WCAG 2.2 adds one more requirement in success criterion 1.4.13: content that appears on hover or focus must be dismissible without moving the pointer or focus. In practice, pressing Escape should hide it. A few lines of JavaScript do this by adding a class on Escape and removing it when the pointer or focus leaves.

When pure CSS is fine

The pure CSS version puts the text in a data-tip attribute and draws it with ::after. It needs only one element and no script, which is handy in prototypes and for purely decorative hints. Screen readers do not read pseudo-element content reliably, so copy the text into an aria-label as well, and use the accessible version for anything important.

Styling the bubble and the arrow

The arrow is a zero-size element with a border on one side, which CSS turns into a triangle. It points toward the trigger, so a tooltip above the button has an arrow along its bottom edge. The distance between bubble and trigger, the arrow size and the corner radius decide whether the tooltip looks attached or floating.

For readability, keep the text at 12 pixels or more and the contrast at least 4.5 to 1. A dark bubble with white text easily reaches 15 to 1 or more; a light bubble needs a border to stand out from a white page.

Timing and animation

A short delay of 100 to 300 milliseconds stops tooltips flashing as the pointer passes over a row of icons. Longer than half a second feels broken. A fade of about 150 milliseconds is enough; a small grow or slide toward the trigger adds a hint of direction. A prefers-reduced-motion rule should remove movement for people who ask their system for less animation.

Building one with the generator

The CSS Tooltip Generator writes all of the above.

  1. Choose the type and side. Accessible or pure CSS, and top, right, bottom or left.
  2. Write the text. Keep it to one short sentence. Type the trigger label too, so the preview looks real.
  3. Style it. Set colours, border, font size, maximum width, radius, arrow size, gap and shadow, or start from a preset: dark, light with border, brand blue, warning or pill.
  4. Set the timing. Pick the animation, delay and duration.
  5. Check it. The preview shows your design on all four sides at once, and the checks report contrast, font size and delay problems.
  6. Copy the code. CSS, HTML and the Escape script for the accessible version.

Edge of the screen

Pure CSS tooltips cannot measure the window, so a tooltip on the right side of a button at the right edge of the screen can be cut off. Choose the side with the most room, which is often top or bottom, and keep the maximum width modest. If tooltips must always stay on screen, keep the generated styles for the look and add a small positioning library that flips them when needed.

A final rule

Never put information only in a tooltip. Error messages, prices, required-field notes and instructions belong in the page. A tooltip is a helpful extra for people who wonder what an icon does, and with focus support and an Escape key it becomes an extra that works for everyone.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages