CSS Tooltips
A tooltip is a tiny floating label that appears on hover or focus. Pure CSS can build a simple one in about 15 lines.
HTML
HTML
<span class="tip"> Hover me <span class="tip-bubble">I'm a tooltip</span> </span>
CSS
CSS
.tip { position: relative; cursor: help; border-bottom: 1px dashed #888; }
.tip-bubble {
position: absolute;
left: 50%;
bottom: calc(100% + 6px);
transform: translateX(-50%);
background: #282a35;
color: #fff;
padding: 6px 10px;
border-radius: 4px;
font-size: 13px;
white-space: nowrap;
opacity: 0;
pointer-events: none;
transition: opacity 0.15s;
}
.tip:hover .tip-bubble,
.tip:focus-within .tip-bubble { opacity: 1; }
The native option: title
| Option | Pros | Cons |
|---|---|---|
title="…" attribute | Zero CSS, accessible. | Hard to style, slow to appear, mobile ignores it. |
| CSS tooltip | Styled to match your brand. | Need ARIA work for full accessibility. |
Popover API (popover attribute) | Modern, accessible, top-layer. | Newer — check browser support. |
Tip: For real product tooltips, add
role="tooltip" and an aria-describedby on the trigger. Screen readers will announce the bubble correctly.Example
Example
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Verdana, sans-serif; }
.box { background: #04AA6D; color: #fff; padding: 20px; border-radius: 6px; }
</style>
</head>
<body>
<h1>CSS Tooltips</h1>
<div class="box">Edit the CSS on the left, then click Run »</div>
</body>
</html>
Try it Yourself »
Exercise
Stop the tooltip from intercepting mouse clicks.
.tip-bubble { opacity: 0;
-events: none; }
The property that controls cursor interaction.
Discussion
Loading…