Tailwind Tooltips That Work With Keyboard and Touch
Updated 2026-10-28. 5 tooltips.
A Tailwind tooltip is a small label in a positioned span next to its trigger, hidden by default and shown with group-hover and group-focus-within. Link it with aria-describedby, add an arrow from a rotated square, and close it on Escape. The versions below open on keyboard focus as well as hover, so nothing is mouse only.
The CSS tooltip with four placements covers most needs: short labels on buttons and links, with no script beyond an Escape handler. Pick the side with the most free space; top is the usual default, and side placements suit narrow vertical toolbars.
Use the React tooltip when you want a short delay before showing, so labels do not flicker as the pointer crosses a toolbar, and when you need one shared component with its own id wiring. The icon button toolbar shows that pattern in place, where the tooltip doubles as the visible name of each icon.
Keep tooltips to plain text. If the content has a heading, a link or anything clickable, use the rich toggletip, which opens on click and stays open until dismissed. For glossary terms in running text, the inline definition version marks each word with a dotted underline and makes it reachable with Tab.
Compare them
| Variant | Built with | Size (gzipped) | Running cost | Browser support |
|---|---|---|---|---|
| Tailwind Tooltip CSS With Arrow On Four Sides | CSS only | 2 KB | Hidden tooltips stay in the DOM; showing one fades opacity and a 4px transform on one element. | All current browsers |
| Inline Definition Tooltips With Help Icon | CSS only | 1.5 KB | Each term carries one hidden span; showing it changes opacity only, so the paragraph never reflows. | All current browsers |
| React Tooltip With Hover Delay And Escape To Close | CSS and a small script | 1.5 KB | One boolean and one timeout per tooltip, cleared on unmount; nothing runs between interactions. | All current browsers |
| Rich Toggletip With Heading And Link | CSS and a small script | 1.2 KB | Document listeners are attached only while the panel is open and removed when it closes. | All current browsers |
| Tooltip On Icon Buttons In An Editor Toolbar | CSS only | 1.3 KB | Tooltips are static spans toggled by opacity; the toolbar adds no listeners beyond Escape and blur. | All current browsers |
Tailwind Tooltip CSS With Arrow On Four Sides
Four buttons on a project board, each with a dark tooltip on a different side: Copy link above, Export to the left, Archive to the right and Pin below. Every tooltip has a small rotated-square arrow pointing at its button, fades in while sliding four pixels into place, and shows on keyboard focus exactly as it does on hover. Escape hides it.
<div class="tt1 tt1-demo">
<h2 class="tt1-title">Q3 roadmap board</h2>
<div class="tt1-grid">
<!-- data-side picks the placement: top, right, bottom or left -->
<div class="tt1-cell"><span class="tt1-wrap" data-side="top">
<button type="button" aria-describedby="tt1-a">Copy link</button>
<span class="tt1-tip" role="tooltip" id="tt1-a">Anyone with the link can view</span>
</span></div>
<div class="tt1-cell"><span class="tt1-wrap" data-side="right">
<button type="button" aria-describedby="tt1-c">Archive</button>
<span class="tt1-tip" role="tooltip" id="tt1-c">Hidden from the board, not deleted</span>
</span></div>
<div class="tt1-cell"><span class="tt1-wrap" data-side="left">
<button type="button" aria-describedby="tt1-b">Export</button>
<span class="tt1-tip" role="tooltip" id="tt1-b">Saves a PDF of this page</span>
</span></div>
<div class="tt1-cell"><span class="tt1-wrap" data-side="bottom">
<button type="button" aria-describedby="tt1-d">Pin</button>
<span class="tt1-tip" role="tooltip" id="tt1-d">Keeps it first in the list</span>
</span></div>
</div>
</div>
<style>
.tt1 { max-width: 36rem; margin: 0 auto; padding: 32px 20px 56px; font-family: ui-sans-serif, system-ui, sans-serif; text-align: center; }
.tt1-title { margin: 0; font-size: 18px; color: #0f172a; }
.tt1-grid { display: grid; gap: 12px; margin-top: 32px; }
@media (min-width: 640px) { .tt1-grid { grid-template-columns: 1fr 1fr; } }
/* Each wrapper sits in its own cell, pushed away from the side its tooltip opens on. */
.tt1-cell { display: flex; height: 128px; border-radius: 12px; background: #f8fafc; box-shadow: inset 0 0 0 1px #e2e8f0; }
.tt1-cell:has([data-side="top"]) { align-items: flex-end; justify-content: center; padding-bottom: 20px; }
.tt1-cell:has([data-side="bottom"]) { align-items: flex-start; justify-content: center; padding-top: 20px; }
.tt1-cell:has([data-side="left"]) { align-items: center; justify-content: flex-end; padding-right: 20px; }
.tt1-cell:has([data-side="right"]) { align-items: center; justify-content: flex-start; padding-left: 20px; }
.tt1-wrap button { min-height: 44px; padding: 0 16px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: #1e293b; font: 500 14px ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
.tt1-wrap button:focus-visible { outline: 2px solid #4f46e5; outline-offset: 2px; }
/* 1. The wrapper is the positioning context. */
.tt1-wrap { position: relative; display: inline-flex; --tt1-gap: 10px; }
/* 2. The tooltip: hidden but in place, ignores the pointer so it never blocks clicks. */
.tt1-tip {
position: absolute; z-index: 10;
width: max-content; max-width: 10rem;
padding: 6px 10px; border-radius: 6px;
background: #0f172a; color: #fff; font-size: 12px; font-weight: 500; line-height: 1.35; text-align: left;
opacity: 0; pointer-events: none;
transition: opacity .15s, transform .15s;
}
/* 3. The arrow: a small square rotated 45deg, half tucked under the tooltip. */
.tt1-tip::after { content: ""; position: absolute; width: 8px; height: 8px; background: inherit; transform: rotate(45deg); }
/* 4. Show on hover AND on keyboard focus. data-closed is set by Escape. */
.tt1-wrap:hover .tt1-tip,
.tt1-wrap:focus-within .tt1-tip { opacity: 1; }
.tt1-demo .tt1-tip { opacity: 1; } /* all shown until the first pointer move or key press */
.tt1-wrap[data-closed] .tt1-tip { opacity: 0; }
/* 5. Placements. Each starts 4px off and slides into place when shown. */
[data-side="top"] .tt1-tip { bottom: 100%; left: 50%; margin-bottom: var(--tt1-gap); transform: translate(-50%, 4px); }
[data-side="top"] .tt1-tip::after { top: 100%; left: 50%; margin: -4px 0 0 -4px; }
[data-side="bottom"] .tt1-tip { top: 100%; left: 50%; margin-top: var(--tt1-gap); transform: translate(-50%, -4px); }
[data-side="bottom"] .tt1-tip::after { bottom: 100%; left: 50%; margin: 0 0 -4px -4px; }
[data-side="left"] .tt1-tip { right: 100%; top: 50%; margin-right: var(--tt1-gap); transform: translate(4px, -50%); }
[data-side="left"] .tt1-tip::after { left: 100%; top: 50%; margin: -4px 0 0 -4px; }
[data-side="right"] .tt1-tip { left: 100%; top: 50%; margin-left: var(--tt1-gap); transform: translate(-4px, -50%); }
[data-side="right"] .tt1-tip::after { right: 100%; top: 50%; margin: -4px -4px 0 0; }
.tt1-wrap:is(:hover, :focus-within)[data-side="top"] .tt1-tip,
.tt1-wrap:is(:hover, :focus-within)[data-side="bottom"] .tt1-tip { transform: translate(-50%, 0); }
.tt1-wrap:is(:hover, :focus-within)[data-side="left"] .tt1-tip,
.tt1-wrap:is(:hover, :focus-within)[data-side="right"] .tt1-tip { transform: translate(0, -50%); }
@media (prefers-reduced-motion: reduce) { .tt1-tip { transition: none; } }
</style>
<script>
(function () {
var root = document.querySelector(".tt1");
function stop() { root.classList.remove("tt1-demo"); }
root.addEventListener("pointermove", stop, { once: true });
root.addEventListener("keydown", stop, { once: true });
})();
/* Escape hides the open tooltip (a WCAG requirement for content on hover or focus). */
document.querySelectorAll(".tt1-wrap").forEach(function (wrap) {
wrap.addEventListener("keydown", function (e) { if (e.key === "Escape") wrap.setAttribute("data-closed", ""); });
wrap.addEventListener("focusout", function () { wrap.removeAttribute("data-closed"); });
wrap.addEventListener("mouseleave", function () { wrap.removeAttribute("data-closed"); });
});
/* Keep every tooltip inside the screen: measure once and on resize, shift it sideways if it would overflow. */
(function () {
var tips = document.querySelectorAll(".tt1 [role=tooltip]");
function fit() {
var w = document.documentElement.clientWidth;
tips.forEach(function (t) {
t.style.translate = "0px 0px";
var r = t.getBoundingClientRect(), dx = 0;
if (r.right > w - 8) dx = w - 8 - r.right;
if (r.left + dx < 8) dx = 8 - r.left;
t.style.translate = dx + "px 0px";
});
}
fit();
window.addEventListener("resize", fit);
})();
</script>
With reduced motion: Tooltips appear and disappear instantly without the short slide toward their trigger.
Running cost: Hidden tooltips stay in the DOM; showing one fades opacity and a 4px transform on one element.
- Change the placement per trigger with `data-side` in the HTML version, or the `side` field in the `tips` array in React.
- Swap `bg-slate-900` (and `#0f172a`) on both the tooltip and its arrow for another colour; the arrow inherits it in the CSS version.
- Adjust the gap between trigger and tooltip with `--tt1-gap`, or `mb-2.5` and its siblings in the `place` map.
- Allow longer text by raising `max-w-[11rem]`; the tooltip wraps rather than running off screen.
Full page for Tailwind Tooltip CSS With Arrow On Four Sides
Inline Definition Tooltips With Help Icon
A short mortgage guide where jargon terms such as LTV, fixed rate and ERC carry a dotted teal underline and a small question mark. Each term is a button inside the sentence, so Tab moves from one to the next, and hovering or focusing shows a plain-English definition above it. The text around the terms stays readable and never shifts.
<article class="tt5">
<h2>Choosing your first mortgage</h2>
<p>
Lenders price deals by your
<span class="tt5-term"><button type="button" aria-describedby="tt5v-ltv">LTV<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M8 1a7 7 0 1 1 0 14A7 7 0 0 1 8 1zm-.8 9.8v1.6h1.6v-1.6zM8 3.6a2.6 2.6 0 0 0-2.6 2.6H7a1 1 0 1 1 1.4.9c-.7.3-1.2 1-1.2 1.8v.4h1.6v-.3c0-.2.1-.4.3-.5A2.6 2.6 0 0 0 8 3.6z"/></svg></button><span class="tt5-tip" role="tooltip" id="tt5v-ltv">Loan to value: the loan as a share of the home's price. A 150,000 loan on a 200,000 home is 75%.</span></span>,
so a bigger deposit usually means a lower rate. Check the
<span class="tt5-term"><button type="button" aria-describedby="tt5v-erc">ERC<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M8 1a7 7 0 1 1 0 14A7 7 0 0 1 8 1zm-.8 9.8v1.6h1.6v-1.6zM8 3.6a2.6 2.6 0 0 0-2.6 2.6H7a1 1 0 1 1 1.4.9c-.7.3-1.2 1-1.2 1.8v.4h1.6v-.3c0-.2.1-.4.3-.5A2.6 2.6 0 0 0 8 3.6z"/></svg></button><span class="tt5-tip" role="tooltip" id="tt5v-erc">Early repayment charge: a fee for paying the loan off or switching before the deal ends.</span></span>
before you sign.
</p>
</article>
<style>
.tt5 { overflow-x: clip; max-width: 36rem; margin: 0 auto; padding: 96px 24px 32px; font-family: ui-sans-serif, system-ui, sans-serif; }
.tt5 h2 { margin: 0 0 16px; font-size: 20px; color: #0f172a; }
.tt5 p { margin: 0; font-size: 16px; line-height: 2; color: #334155; }
.tt5-term { position: relative; display: inline-block; }
/* The term is a real button styled as text, so Tab reaches it. Dotted underline says "there is more here". */
.tt5-term button { display: inline-flex; align-items: baseline; gap: 4px; padding: 0; border: 0; background: none; font: inherit; font-weight: 500; color: #134e4a; text-decoration: underline dotted #0d9488 2px; text-underline-offset: 4px; cursor: help; }
.tt5-term button:hover { text-decoration-style: solid; }
.tt5-term button:focus-visible { outline: 2px solid #0d9488; outline-offset: 2px; border-radius: 2px; }
.tt5-term svg { width: 14px; height: 14px; fill: #0d9488; transform: translateY(2px); }
.tt5-tip { position: absolute; bottom: 100%; left: 0; z-index: 10; width: 15rem; margin-bottom: 8px; padding: 12px; border-radius: 8px; background: #042f2e; color: #f0fdfa; font-size: 12px; font-weight: 400; line-height: 1.6; opacity: 0; pointer-events: none; transition: opacity .15s; }
.tt5-term:hover .tt5-tip, .tt5-term:focus-within .tt5-tip { opacity: 1; }
.tt5-term[data-closed] .tt5-tip { opacity: 0; }
@media (prefers-reduced-motion: reduce) { .tt5-tip { transition: none; } }
</style>
<script>
document.querySelectorAll(".tt5-term").forEach(function (t) {
t.addEventListener("keydown", function (e) { if (e.key === "Escape") t.setAttribute("data-closed", ""); });
t.addEventListener("focusout", function () { t.removeAttribute("data-closed"); });
t.addEventListener("mouseleave", function () { t.removeAttribute("data-closed"); });
});
/* Keep every tooltip inside the screen: measure once and on resize, shift it sideways if it would overflow. */
(function () {
var tips = document.querySelectorAll(".tt5 [role=tooltip]");
function fit() {
var w = document.documentElement.clientWidth;
tips.forEach(function (t) {
t.style.translate = "0px 0px";
var r = t.getBoundingClientRect(), dx = 0;
if (r.right > w - 8) dx = w - 8 - r.right;
if (r.left + dx < 8) dx = 8 - r.left;
t.style.translate = dx + "px 0px";
});
}
fit();
window.addEventListener("resize", fit);
})();
</script>
With reduced motion: Definitions appear at full strength straight away rather than fading in over the paragraph.
Running cost: Each term carries one hidden span; showing it changes opacity only, so the paragraph never reflows.
- Add a term by writing a new key in the `terms` object and wrapping the word in `<Term id="...">`.
- Change `decoration-dotted` to `decoration-dashed`, or remove the help icon svg if the underline is enough.
React Tooltip With Hover Delay And Escape To Close
A small reusable Tooltip component shown on the status badges of a gardening blog's post list. Hovering a badge waits 350 milliseconds before opening, so sweeping the pointer across the list causes no flicker, while tabbing to a badge opens it at once. A short close delay lets the pointer travel onto the tooltip, and Escape closes it.
<ul class="tt2">
<li><span>Planting garlic in October</span>
<span class="tt2-wrap">
<button type="button" class="tt2-badge tt2-live" aria-describedby="tt2-a">Published</button>
<span class="tt2-tip" role="tooltip" id="tt2-a">Live on the site since 12 October.</span>
</span>
</li>
<li><span>What to sow under glass</span>
<span class="tt2-wrap">
<button type="button" class="tt2-badge tt2-soon" aria-describedby="tt2-b">Scheduled</button>
<span class="tt2-tip" role="tooltip" id="tt2-b">Goes live on Friday at 07:00 for subscribers first.</span>
</span>
</li>
</ul>
<style>
.tt2 { max-width: 36rem; margin: 0 auto; padding: 40px 20px 8px; list-style: none; font-family: ui-sans-serif, system-ui, sans-serif; }
.tt2 li { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 28px 0 14px; border-bottom: 1px solid #ecfccb; font-size: 14px; color: #1e293b; }
.tt2-wrap { position: relative; display: inline-flex; }
.tt2-badge { min-height: 32px; padding: 0 12px; border: 0; border-radius: 999px; font: 600 12px ui-sans-serif, system-ui, sans-serif; cursor: default; }
.tt2-badge:focus-visible { outline: 2px solid #047857; outline-offset: 2px; }
.tt2-live { background: #d1fae5; color: #064e3b; }
.tt2-soon { background: #fef3c7; color: #78350f; }
.tt2-tip { position: absolute; bottom: 100%; left: 50%; z-index: 10; width: max-content; max-width: 14rem; margin-bottom: 8px; padding: 8px 12px; border-radius: 8px; background: #022c22; color: #ecfdf5; font-size: 12px; line-height: 1.35; opacity: 0; pointer-events: none; transform: translate(-50%, 4px); transition: opacity .15s, transform .15s; }
.tt2-tip::after { content: ""; position: absolute; top: 100%; left: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; background: inherit; transform: rotate(45deg); }
/* Script toggles data-open; the tooltip accepts the pointer while open so people can move onto it. */
.tt2-wrap[data-open] .tt2-tip { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .tt2-tip { transition: none; } }
</style>
<script>
(function () {
var OPEN_DELAY = 350, CLOSE_DELAY = 120;
document.querySelectorAll(".tt2-wrap").forEach(function (wrap) {
var t;
function set(open, ms) {
clearTimeout(t);
t = setTimeout(function () { wrap.toggleAttribute("data-open", open); }, ms);
}
wrap.addEventListener("pointerenter", function () { set(true, OPEN_DELAY); }); /* delay stops flicker */
wrap.addEventListener("pointerleave", function () { set(false, CLOSE_DELAY); }); /* grace to reach the tip */
wrap.addEventListener("focusin", function () { set(true, 0); }); /* keyboard: no delay */
wrap.addEventListener("focusout", function () { set(false, 0); });
wrap.addEventListener("keydown", function (e) { if (e.key === "Escape") set(false, 0); });
});
})();
/* Keep every tooltip inside the screen: measure once and on resize, shift it sideways if it would overflow. */
(function () {
var tips = document.querySelectorAll(".tt2 [role=tooltip]");
function fit() {
var w = document.documentElement.clientWidth;
tips.forEach(function (t) {
t.style.translate = "0px 0px";
var r = t.getBoundingClientRect(), dx = 0;
if (r.right > w - 8) dx = w - 8 - r.right;
if (r.left + dx < 8) dx = 8 - r.left;
t.style.translate = dx + "px 0px";
});
}
fit();
window.addEventListener("resize", fit);
})();
</script>
With reduced motion: Tooltips still wait for the hover delay but then appear without fading or sliding.
Running cost: One boolean and one timeout per tooltip, cleared on unmount; nothing runs between interactions.
- Tune `OPEN_DELAY` and `CLOSE_DELAY` at the top; 300 to 500ms to open feels deliberate without being slow.
- The trigger is passed as a render function, so any element receives `aria-describedby` without an extra wrapper button.
Rich Toggletip With Heading And Link
A property listing shows its energy rating with a round help button beside it. Pressing the button opens a white panel with a short heading, two sentences on what the rating means and a link to the full certificate. It stays open until you press the button again, press Escape or click elsewhere, which makes it usable on phones and safe for a link inside.
<div class="tt3">
<p class="tt3-addr">14 Larch Close, two bedrooms</p>
<div class="tt3-row">
<h2 class="tt3-h">Energy rating: B (84)</h2>
<div class="tt3-wrap">
<!-- A toggletip opens on click, so it works on touch and can hold a link. -->
<button type="button" class="tt3-btn" aria-expanded="true" aria-controls="tt3-panel" aria-label="About energy ratings">?</button>
<div class="tt3-panel" id="tt3-panel" role="region" aria-label="About energy ratings">
<h3>What the B rating means</h3>
<p>Ratings run from A, the most efficient, to G. A B home typically has wall and loft insulation and a modern boiler.</p>
<a href="#">Read the full certificate</a>
</div>
</div>
</div>
<p class="tt3-addr">Estimated heating cost £610 a year.</p>
</div>
<style>
.tt3 { max-width: 28rem; margin: 0 auto; padding: 24px 24px 200px; font-family: ui-sans-serif, system-ui, sans-serif; }
.tt3-addr { margin: 0; font-size: 14px; color: #475569; }
.tt3-row { position: relative; display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.tt3-h { margin: 0; font-size: 18px; color: #0f172a; }
.tt3-btn { width: 40px; height: 40px; border: 2px solid #be123c; border-radius: 50%; background: #fff; color: #be123c; font: 700 16px ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
.tt3-btn:focus-visible { outline: 3px solid #e11d48; outline-offset: 2px; }
.tt3-panel { position: absolute; left: 0; top: 100%; z-index: 10; box-sizing: border-box; width: 100%; max-width: 20rem; margin-top: 8px; padding: 16px; border: 1px solid #e2e8f0; border-radius: 12px; background: #fff; box-shadow: 0 16px 32px -12px rgb(15 23 42 / .3); }
.tt3-btn[aria-expanded="false"] + .tt3-panel { display: none; }
.tt3-panel h3 { margin: 0; font-size: 14px; color: #0f172a; }
.tt3-panel p { margin: 6px 0 12px; font-size: 14px; line-height: 1.6; color: #475569; }
.tt3-panel a { font-size: 14px; font-weight: 600; color: #be123c; text-underline-offset: 4px; }
</style>
<script>
(function () {
var wrap = document.querySelector(".tt3-wrap");
if (!wrap) return;
var btn = wrap.querySelector(".tt3-btn");
function set(open) { btn.setAttribute("aria-expanded", open ? "true" : "false"); }
btn.addEventListener("click", function () { set(btn.getAttribute("aria-expanded") !== "true"); });
/* Close on a click outside, and on Escape (returning focus to the button). */
document.addEventListener("pointerdown", function (e) { if (!wrap.contains(e.target)) set(false); });
document.addEventListener("keydown", function (e) {
if (e.key === "Escape" && btn.getAttribute("aria-expanded") === "true") { set(false); btn.focus(); }
});
})();
</script>
With reduced motion: The panel has no animation; it simply shows and hides when the button is pressed.
Running cost: Document listeners are attached only while the panel is open and removed when it closes.
- Widen the panel by raising `max-w-xs` (20rem in the HTML version); it is anchored to the heading row, so it never runs off a phone screen.
- Start it closed by setting the initial state to `false` (or `aria-expanded="false"` in the HTML).
Tooltip On Icon Buttons In An Editor Toolbar
A text editor toolbar of icon-only buttons for bold, italic, link, bulleted list and undo. Hovering or tabbing to an icon shows a small dark label under it with the action name and its keyboard shortcut in a key cap. The label is wired with aria-labelledby, so the same words a sighted user reads become the button's name for screen readers.
<div class="tt4">
<div class="tt4-bar" role="toolbar" aria-label="Formatting">
<!-- aria-labelledby points at the tooltip, so the tooltip text IS the button's name. -->
<span class="tt4-wrap">
<button type="button" aria-labelledby="tt4v-bold"><svg viewBox="0 0 20 20" aria-hidden="true"><path d="M6 4h5a3.5 3.5 0 0 1 2.5 6A3.8 3.8 0 0 1 12 17H6zm2.5 2.2v3.3H11a1.6 1.6 0 0 0 0-3.3zm0 5.4v3.2H12a1.6 1.6 0 0 0 0-3.2z"/></svg></button>
<span class="tt4-tip" role="tooltip" id="tt4v-bold">Bold <kbd>Ctrl B</kbd></span>
</span>
<span class="tt4-wrap">
<button type="button" aria-labelledby="tt4v-italic"><svg viewBox="0 0 20 20" aria-hidden="true"><path d="M8 4h7v2h-2.4l-2.2 9H13v2H6v-2h2.4l2.2-9H8z"/></svg></button>
<span class="tt4-tip" role="tooltip" id="tt4v-italic">Italic <kbd>Ctrl I</kbd></span>
</span>
<span class="tt4-wrap">
<button type="button" aria-labelledby="tt4v-undo"><svg viewBox="0 0 20 20" aria-hidden="true"><path d="M8 5L3 9.5 8 14v-3h4a3 3 0 0 1 0 6h-2v2h2a5 5 0 0 0 0-10H8z"/></svg></button>
<span class="tt4-tip" role="tooltip" id="tt4v-undo">Undo <kbd>Ctrl Z</kbd></span>
</span>
</div>
<p class="tt4-text">The Saturday market moves to Mill Square from 3 November while the bridge is repaired.</p>
</div>
<style>
.tt4 { max-width: 36rem; margin: 24px auto 56px; border: 1px solid #e4e4e7; border-radius: 16px; background: #fff; font-family: ui-sans-serif, system-ui, sans-serif; }
.tt4-bar { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid #e4e4e7; }
.tt4-wrap { position: relative; }
.tt4-wrap button { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 8px; background: transparent; color: #3f3f46; cursor: pointer; }
.tt4-wrap button:hover { background: #f4f4f5; }
.tt4-wrap button:focus-visible { outline: 2px solid #7c3aed; outline-offset: 0; }
.tt4-wrap svg { width: 20px; height: 20px; fill: currentColor; }
/* Below the button, centred, never wraps (labels are short). */
.tt4-tip { position: absolute; top: 100%; left: 50%; z-index: 10; display: flex; align-items: center; gap: 8px; margin-top: 8px; padding: 6px 8px; border-radius: 6px; background: #18181b; color: #fff; font-size: 12px; font-weight: 500; white-space: nowrap; opacity: 0; pointer-events: none; transform: translateX(-50%); transition: opacity .1s; }
.tt4-tip kbd { padding: 1px 4px; border-radius: 4px; background: #3f3f46; color: #e4e4e7; font: 11px ui-sans-serif, system-ui, sans-serif; }
.tt4-wrap:hover .tt4-tip, .tt4-wrap:focus-within .tt4-tip { opacity: 1; }
.tt4-wrap[data-closed] .tt4-tip { opacity: 0; }
.tt4-text { margin: 0; padding: 20px; font-size: 14px; line-height: 1.6; color: #3f3f46; }
@media (prefers-reduced-motion: reduce) { .tt4-tip { transition: none; } }
</style>
<script>
document.querySelectorAll(".tt4-wrap").forEach(function (w) {
w.addEventListener("keydown", function (e) { if (e.key === "Escape") w.setAttribute("data-closed", ""); });
w.addEventListener("focusout", function () { w.removeAttribute("data-closed"); });
w.addEventListener("mouseleave", function () { w.removeAttribute("data-closed"); });
});
</script>
With reduced motion: Each label appears instantly under its icon instead of a quick fade.
Running cost: Tooltips are static spans toggled by opacity; the toolbar adds no listeners beyond Escape and blur.
- Edit the `tools` array to change names, shortcuts and icon paths in one place.
- Move the label above the icons by swapping `top-full mt-2` for `bottom-full mb-2`.
Performance notes
A CSS tooltip is an absolutely positioned element that fades and shifts a few pixels with opacity and transform, so showing one costs a single composited layer and no layout. Leaving tooltips in the DOM but hidden is cheaper than creating and destroying them on every hover.
The React versions keep one piece of state per tooltip and a single timeout for the delay, cleared on unmount. If a page has hundreds of triggers, such as a data table, render one shared tooltip and move it to the active trigger instead of mounting one per cell.
Questions
How do I make a tooltip with only CSS?
Give the trigger wrapper position: relative, put the tooltip inside it with position: absolute, opacity: 0 and pointer-events: none, then set opacity to 1 on :hover and :focus-within of the wrapper. Place it with bottom: 100% and a translate to centre it, and draw the arrow with a small rotated square.
Are tooltips accessible?
They can be. Show them on keyboard focus as well as hover, connect them with aria-describedby and role="tooltip", let Escape hide them, and keep them open while the pointer moves onto the tooltip. Never put the only copy of important information in a tooltip, because touch users may never see it.
What is the difference between a tooltip and a toggletip?
A tooltip appears on hover or focus and describes its trigger with short text. A toggletip opens when clicked, can hold a heading or a link, and stays open until it is closed, which makes it usable on touch screens.
How do I stop a tooltip going off the screen?
Choose a side with room, cap its width with max-width and allow wrapping, and on small screens switch placement with a media query. For tooltips near the edge of a scrolling area, a positioning library or CSS anchor positioning can flip it automatically.
Do I need a library for a React tooltip?
Not for simple cases. State for open or closed, a timeout for the delay, focus and blur handlers, an Escape key handler and an id for aria-describedby cover most tooltips in about forty lines. A library helps when you need collision detection inside scrolling containers.
More collections: HTML and CSS Buttons: 8 Styles to Copy, Dark Mode Toggle Switches in CSS and React, Gradient Borders in CSS, Rounded and Animated. All content sections. Build your site free to have a full site built around them.
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App