Layout Intermediate

Hover tooltips without JavaScript events

Tooltips required JavaScript mouseenter/mouseleave listeners, focus handling, and manual positioning. Now popover=hint with the interestfor attribute gives you declarative, accessible hover UI.

Old 14 lines
1/* JS: manage hover, focus, and position */
2btn.addEventListener('mouseenter', () => {
3  tip.hidden = false;
4  positionTooltip(btn, tip);
5});
6btn.addEventListener('mouseleave', () => {
7  tip.hidden = true;
8});
9btn.addEventListener('focus', /* … */);
10btn.addEventListener('blur', /* … */);
Modern
5 lines
1<button interestfor="tip">
2  Hover me
3</button>
4<div id="tip" popover=hint>
5  Tooltip content</div>
hover the button to see the tooltip
CSS-only tooltip with popover=hint ✦
popover="hint" + interestfor

All input modes

The browser triggers on hover (mouse), focus (keyboard), and long-press (touch). You write zero event handling.

Non-destructive

Hint popovers don't close other open auto or manual popovers. Layered UI coexists naturally.

Built-in delay

The interest-delay property (default 0.5s) prevents accidental triggers. Configurable with CSS.

Browser Support
72%
Chrome Edge Firefox 🔜 Safari 🔜
View on caniuse.com →
Lines Saved
14 → 5
No event listeners
Old Approach
JS event listeners
mouseenter, mouseleave, focus, blur
Modern Approach
popover=hint
interestfor + popover=hint

How it works

Building accessible tooltips required at least four event listeners (mouseenter, mouseleave, focus, blur), a delay mechanism to prevent flicker, position logic, and careful DOM management. Libraries like Tippy.js exist specifically because this is so tedious to get right.

The new popover=hint type paired with the interestfor attribute handles all of this declaratively. The interestfor attribute on the trigger element points to the tooltip's ID. The browser shows the popover when the user 'shows interest' (hover, focus, long-press) and hides it when interest ends. Customize the delay with the interest-delay CSS property. Unlike popover=auto, hint popovers coexist with other open popovers.

ESC