CSS Tooltip

Pure CSS tooltip on hover, no JavaScript.

Hover me This is a tooltip
Tailwind CSS
<div class="flex items-center gap-8 py-8">
  <span class="relative group cursor-help">
    <span class="text-sm font-semibold text-slate-700 dark:text-slate-200 border-b border-dotted border-slate-400">Hover me</span>
    <span class="absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-3 py-1.5 rounded-lg bg-slate-900 text-white text-xs font-medium whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none">
      This is a tooltip
      <span class="absolute top-full left-1/2 -translate-x-1/2 border-4 border-transparent border-t-slate-900"></span>
    </span>
  </span>
  <button class="relative group w-10 h-10 rounded-full bg-indigo-100 text-indigo-600 font-bold flex items-center justify-center">
    ?
    <span class="absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-3 py-1.5 rounded-lg bg-slate-900 text-white text-xs font-medium whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none">Help text here</span>
  </button>
</div>

Free to use in personal and commercial projects. No attribution required.

About this css tooltip

Tooltips explain the unexplained: icon buttons, truncated text, form fields with format requirements. This css tooltip is pure group-hover, no JavaScript. The tooltip sits absolutely above the trigger, fades in on hover, and includes the little arrow pointer made from a rotated border trick.

The pattern is endlessly reusable. Wrap any element in a relative group span, add the absolutely-positioned tooltip, and it just works. The pointer-events-none ensures the tooltip never blocks clicks, and whitespace-nowrap keeps it on one line.

Keep tooltips short: one line, under 60 characters. If you need paragraphs, use a popover instead. And never put essential information only in a tooltip, because touch users and keyboard users may never trigger it.

Dense interfaces cannot label everything; full labels on every icon would turn a toolbar into a paragraph. Tooltips solve it with progressive disclosure at the smallest scale: the explanation hides until the moment of curiosity, when hovering the icon reveals it. They let dashboards stay compact while remaining learnable.

The trigger is a relative group span with cursor-help. The tooltip itself is absolute bottom-full left-1/2 -translate-x-1/2 mb-2, styled px-3 py-1.5 rounded-lg bg-slate-900 text-white text-xs font-medium whitespace-nowrap, starting at opacity-0 and fading to group-hover:opacity-100 with transition-opacity. The little arrow is a span using the border trick: border-4 border-transparent border-t-slate-900. Pointer-events: none keeps the tooltip from ever intercepting clicks.

Add group-hover:delay-300 so tooltips don't flash while the mouse travels across a toolbar; instant tooltips on every icon create a strobe effect. Position variants are one class away: top-full drops it below, left-full puts it right. For touch users, also reveal on focus with group-focus-within, since hover doesn't exist there.

The content mistake is writing paragraphs inside tooltips. A tooltip that needs scrolling has outgrown its job; it should become a popover or a help section. Keep it to one line under 60 characters. If the information is essential rather than supplementary, it doesn't belong in a tooltip at all.

Design notes

When to use

Tooltips fit short, supplementary explanations for controls whose purpose is almost clear, like what an icon button does or what an abbreviation stands for. The dotted underline on the trigger quietly hints that extra information is hiding there. They shine in dense interfaces like dashboards where every pixel counts and a full label would clutter the layout.

What to avoid

Never put essential information only in a tooltip, because touch users and keyboard users may never trigger it. Do not write paragraphs inside one either, a tooltip that needs scrolling has outgrown its job and should become a popover or a help section. Also avoid tooltips on plain body text where they fire accidentally while reading.

Accessibility

This tooltip only appears on hover, so keyboard and screen reader users miss it entirely. Pair the trigger with a focusable element and show the tooltip on focus too, and consider aria-describedby for information that actually matters.

Variants

Same component, different looks. Preview each one live and copy the code you like.

Bottom

Place the tooltip below when there is no room above, like near a header.

Hover me This is a tooltip
Tailwind CSS

Light

The light tooltip suits minimal interfaces where dark tooltips feel heavy.

Hover me This is a tooltip
Tailwind CSS

Rich

Use the rich tooltip for feature explanations that need a title and detail.

Pro plan Pro plan Unlimited projects, priority support, and custom domains included.
Tailwind CSS

Where to use it

  • ✓ Icon button labels
  • ✓ Form field hints
  • ✓ Truncated text expansion
  • ✓ Feature explanations

Frequently asked questions

How do I make a tooltip with only CSS?

Wrap the trigger in a relative group element. Add an absolutely positioned tooltip div that is opacity-0 by default and opacity-100 on group-hover. No JavaScript needed.

How do I make the tooltip arrow?

Use a small div with borders: border-4 border-transparent with one colored side (border-t-slate-900 for a downward arrow). Position it at the tooltip edge.

Are CSS-only tooltips accessible?

Partially. They work for mouse users but not keyboard or touch. For critical info, also use aria-label on the trigger so screen readers announce it.

How do I add a delay before a tooltip appears?

Add transition-delay of 200 to 400ms to the tooltip's opacity and visibility transition. The tooltip then only shows when the user intentionally hovers, not while the cursor passes over. Keep the hide delay at 0 so it disappears instantly on mouseout.

Do CSS hover tooltips work on mobile?

Not reliably, because touch screens have no hover state. Pair every :hover rule with :focus so keyboard and tap-focus users get the tooltip, or add a tap-to-toggle with JavaScript. For critical information, prefer always-visible helper text over a tooltip on mobile layouts.

How do I make a multiline tooltip?

Give the tooltip a fixed max-width like 200px and set white-space to normal so text wraps. Center it with left 50% and translateX(-50%). For long content consider a click-triggered popover instead, since tooltips are meant for short hints.

Customization tips

Position with top-full for below, left-full for right side. Add delay with group-hover:delay-300 so tooltips do not flash during mouse travel. For rich content, replace the span with a wider div.