Hover Tooltip
悬停提示气泡
A small label appears beside a control to explain what it does.
Where to use it
Explain an unfamiliar icon or a short technical term. Keep the label short and show it on keyboard focus. Put instructions that users need to complete a task directly in the interface.
Practical example
In an invoice editor, hovering or focusing the calendar icon beside a due-date field shows the label Choose due date. That gives first-time users a plain-language explanation of the icon.
Related design tip
Make optional help open by touchAI prompt
Add Hover Tooltip to [target]. Anchor a short role="tooltip" label to the trigger and reference it with aria-describedby. Open on hover and focus, dismiss with Escape, and keep essential content elsewhere. Keep the content readable in reduced-motion mode and preserve keyboard navigation.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hover Tooltip</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.target {
position: relative;
display: grid;
place-items: center;
width: min(100%, 208px);
min-height: 84px;
padding: 10px;
color: #f5efff;
border: 1px solid #aa91ee80;
border-radius: 13px;
background: #29213f;
cursor: pointer;
font: 680 15px system-ui, sans-serif;
}
.target[aria-pressed="true"] { outline: 2px solid #d9c9ff; outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) {
.target, .target *, .target::before, .target::after, .target *::before, .target *::after {
transition: none !important;
animation: none !important;
}
}
.tip-wrap { position: relative; margin-top: 32px; }
.target { width: 56px; min-height: 48px; font-size: 22px; }
#tip {
position: absolute; bottom: calc(100% + 9px); left: 50%; z-index: 1; width: max-content;
max-width: 180px; padding: 6px 10px; border-radius: 6px;
transform: translate(-50%, 4px); opacity: 0; background: #e0d4ff;
color: #201435; font-size: 12px; pointer-events: none; transition: transform .18s, opacity .18s;
}
.tip-wrap:not([data-dismissed]):is(:hover,:focus-within,[data-open]) #tip { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
#tip::after { content: ''; position: absolute; inset: 100% 0 auto; height: 10px; }
@media (prefers-reduced-motion: reduce) { #tip { transition: none; } }
</style>
</head>
<body>
<main class="demo">
<div class="tip-wrap">
<span id="tip" role="tooltip">Keyboard shortcuts</span>
<button class="target" type="button" aria-label="Help" aria-describedby="tip">?</button>
</div>
</main>
<script>
const wrapper = document.querySelector('.tip-wrap');
const trigger = wrapper.querySelector('button');
trigger.addEventListener('click', () => {
if (wrapper.toggleAttribute('data-open')) wrapper.removeAttribute('data-dismissed');
else wrapper.setAttribute('data-dismissed', '');
});
trigger.addEventListener('keydown', (event) => {
if (event.key !== 'Escape') return;
wrapper.removeAttribute('data-open');
wrapper.setAttribute('data-dismissed', '');
});
wrapper.addEventListener('pointerleave', () => wrapper.removeAttribute('data-dismissed'));
wrapper.addEventListener('focusout', () => wrapper.removeAttribute('data-dismissed'));
</script>
</body>
</html>Original example by UI Skills