On this page
CSS Tooltips and Popovers: Popover API, Anchor Positioning and Accessible Overlays
Tooltips vs popovers
A tooltip is a small text hint that appears when an element is hovered or focused. A popover is a larger floating panel that can contain links, buttons, forms or rich content, and is opened by an explicit action such as a click. Choosing the right one is the most important design decision, because each has different accessibility rules.
Focus keyword: CSS tooltips and popovers. Related trending keywords: Popover API, popovertarget, anchor positioning, position-area, top layer, light dismiss, toggletip, @starting-style popover animation, WCAG 1.4.13.
When to use which
- Tooltip: short, non-essential, text-only supplementary info for a control (for example the name of an icon button). Never put interactive content inside a tooltip.
- Toggletip: a click-activated small message, good for help icons. Content is announced with a live region.
- Popover: rich or interactive content like menus, filters, profile cards and date pickers.
- Dialog: modal content that needs a decision. It blocks the page, unlike a popover.
Tooltip accessibility rules
- Show on hover and keyboard focus, not hover only.
- Connect it with
aria-describedbyand give the tooltiprole='tooltip'. For icon buttons, the name should usually come fromaria-labeland the tooltip is an extra visual. - WCAG 1.4.13 Content on Hover or Focus: the extra content must be dismissible (Escape closes it without moving pointer or focus), hoverable (the pointer can move onto it without it disappearing) and persistent (it stays until dismissed or no longer relevant).
- Do not put essential information only in a tooltip, since touch users cannot hover.
The Popover API
The HTML popover attribute turns any element into a popover that is shown in the top layer, so it is never clipped by overflow: hidden and does not need z-index. Connect a button with popovertarget='id'; no JavaScript is required.
popover(same aspopover='auto'): light dismiss (click outside or press Escape closes it) and only one auto popover is open at a time.popover='manual': no light dismiss, you control opening and closing. Good for toasts.- Methods:
showPopover(),hidePopover(),togglePopover(). Events:beforetoggleandtoggle. - Style the open state with
:popover-openand the backdrop with::backdrop. - The browser provides focus return and basic accessibility, but you still need a good trigger label and meaningful content.
Animating popovers
Because popovers change between display: none and shown, animate them with @starting-style and transition-behavior: allow-discrete: set transition: opacity .25s, transform .25s, overlay .25s allow-discrete, display .25s allow-discrete;. Define the closed style on [popover], the open style on :popover-open, and the starting style inside @starting-style.
CSS anchor positioning
Anchor positioning lets you attach a floating element to another element in pure CSS, replacing JavaScript positioning libraries in many cases. Give the trigger anchor-name: --tip; on the popover use position: fixed; position-anchor: --tip; position-area: top; (or bottom, left, right, top span-right). Use position-try-fallbacks: flip-block so it flips when there is no room. Because support is still growing, treat it as progressive enhancement: wrap it in @supports (position-anchor: --a) and keep a simple fallback position.
Best practices
- Keep tooltip text short (under about 80 characters).
- Provide sufficient contrast and a pointer arrow only if it adds clarity.
- Do not cover the trigger itself or important nearby content.
- Respect
prefers-reduced-motion. - Test with keyboard only, a screen reader and on touch devices.
Quick summary
Use tooltips for short, non-essential hints with hover and focus support, toggletips for click-activated help, and the Popover API plus anchor positioning for rich floating panels. That gives accessible CSS tooltips and popovers with very little JavaScript.
Press Run to execute.
Press Run to execute.
Press Run to execute.
Press Run to execute.
Press Run to execute.
Finish the tooltip so it shows on hover and on keyboard focus, is connected with aria-describedby, stays visible when the pointer moves onto the tooltip (hoverable) and closes when Escape is pressed (dismissible).
Press Run to execute.
Show expected output
The tooltip shows on hover and focus, remains visible while the pointer is over it, and disappears when Escape is pressed.This is a self-check — compare your result with the expected output above.
Was this page helpful?