Skip to content

Pure CSS Tooltips

JavaScript-free tooltips driven by data attributes, with top, right, bottom and left placement, arrows, color tones and hover or focus triggers.

Also known as: hover tooltip, hover help bubble, data attribute tooltip, popover hint

Pure CSS Tooltips live demo

Open in new tab

Pure CSS code (HTML, CSS)

Lightweight tooltips made with pure CSS and no JavaScript at all. Add a class and a data-tooltip attribute to any button, link or text and a small bubble with an arrow appears on hover and keyboard focus, on the top, right, bottom or left side. They suit icon toolbars, form hints, glossary terms and compact dashboards.

How it works

Every tooltip is two pseudo-elements on the element with .tt-tip. ::after prints the text with content: attr(data-tooltip), and ::before draws the arrow as a zero-size box with one colored border. Both are absolutely positioned against the element (.tt-tip sets position: relative) and start with opacity: 0 and visibility: hidden.

The side is chosen with data-tooltip-pos. Top is the default; bottom, left and right move the bubble and switch which border of the arrow gets the color. Each side also sets two custom properties, --tt-hide and --tt-show, which hold the transform before and after showing, so the bubble slides a few pixels toward its final spot as it fades in.

The bubble appears on :hover, on :focus-visible, or permanently when the element has the data-tooltip-open attribute. The demo uses that attribute on the four direction tiles so every side is visible at once, while the dark .tt-toolbar and the inline .tt-term show the usual hover and focus behaviour. The text wraps automatically once it reaches --tt-max-width.

Customization

  • data-tooltip on any .tt-tip element: the tooltip text.
  • data-tooltip-pos="top|right|bottom|left": the side where the bubble appears.
  • data-tooltip-tone="light" or "accent": a white bubble with dark text, or a pink accent bubble; add your own tone by setting --tt-bg and --tt-color.
  • --tt-bg and --tt-color on .tt-tip: default bubble and text colors for all tooltips.
  • --tt-offset and --tt-arrow: the gap between element and bubble, and the arrow size.
  • --tt-max-width: the width at which long text starts to wrap.
  • --tt-delay and --tt-speed: the hover delay before showing and the fade duration.
  • data-tooltip-open: remove it from the four .tt-btn buttons to make them hover-only like the rest.

Use cases

  • Icon toolbars: buttons show a short label bubble on hover and keyboard focus
  • Form hints: a small tooltip explains a field with a top, right, bottom or left arrow
  • Glossary terms: inline words show their definition on hover and focus
  • Compact dashboards: light and accent tones mark different kinds of help text without any script

Accessibility

Text in pseudo-elements is not reliably announced by screen readers, so the tooltip must never be the only source of information. The icon buttons in the toolbar carry an aria-label with the same text, and the glossary term uses aria-describedby pointing to a visually hidden .tt-sr span. Tooltips open on :focus-visible, so keyboard users see the same hints as mouse users, and the focusable term has tabindex="0". All controls show a pink focus outline. With prefers-reduced-motion: reduce the slide and delay are removed.

Usage notes

Because the tooltip is part of the element, a parent with overflow: hidden will clip it; .tt-demo uses overflow-x: clip only to stop hidden bubbles from causing sideways scrolling on phones. Pseudo-elements cannot be dismissed with Escape; if you need that, add a small script that toggles a class. Elements such as input and img cannot have pseudo-elements, so wrap them in a span.tt-tip.

Pure CSS Tooltips at a glance

Framework
Pure CSS
Code
HTML, CSS
JavaScript
Not needed, CSS only
Dependencies
None
Layout
Responsive, works on mobile
Category
Tooltips & Popovers
License
Free for personal and commercial use

Questions about this template

Can I use the Pure CSS Tooltips code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear and add the CSS to your stylesheet. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. It is built with HTML and CSS only, so there is no JavaScript to load.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Pure CSS Tooltips – free Pure CSS tooltip & popover template
Pure CSS Tooltips · free Pure CSS tooltip & popover template

More Tooltips & Popovers

User Hover Card Popover with Photo – free Bootstrap 5 tooltip & popover template

User Hover Card Popover with Photo

Bootstrap 5 popover hover card showing a user photo, cover band, bio, follower stats and a working follow button.

Popover with Rich Content – free Bootstrap 5 tooltip & popover template

Popover with Rich Content

Bootstrap 5 popovers with HTML content: profile card with buttons, inline help with links and a delete confirmation, with focus handling.