CSS Tooltip Generator

Set the text, the side the tooltip appears on, the colors and the size of the arrow, and get the HTML and CSS to paste into your page. The tooltip is pure CSS, with no JavaScript: the text sits in a data attribute, a pseudo-element draws the bubble and a second one draws the arrow.

What you enter

  • Text on the page
  • Tooltip text
  • Side
  • Background color
  • Text color
  • Padding, top and bottom
  • Padding, left and right
  • Corner radius
  • Font size
  • Arrow size
  • Gap between element and arrow
  • Maximum width (0 keeps it on one line)
  • Show on
  • Class name

How it works

  1. Type the label the tooltip is attached to and the text it should show.
  2. Choose the side it appears on (top, right, bottom or left), then set the colors, padding, corner radius, font size, arrow size and gap.
  3. Pick whether it appears on hover only, or on hover and keyboard focus. Set a maximum width if long tips should wrap.
  4. Copy the code into your page. Paste the style block into your stylesheet and put the element where you want the tooltip.

Choosing where the tooltip goes

Top is the common default because the pointer and the hand do not cover it. Bottom suits elements near the top of a page where there is no room above. Left and right are for items in a narrow column, such as icons in a toolbar, where a tip above or below would run into neighbouring items.

Think about what is next to the element. A tooltip is positioned relative to its trigger and is not aware of the window, so if the trigger sits at the edge of the screen, a centred tip can extend past it. Test the edge cases by dragging the browser window narrower.

Colors and contrast

A tooltip is small and appears briefly, so it must be easy to read at a glance. Dark background with white text is the usual choice and gives strong contrast. Check any other pair with a contrast checker, aiming for at least 4.5 to 1 for text of this size.

The arrow takes its color from the background color you choose, so the bubble and the arrow always match. If your page has a coloured background, pick a tooltip color that stands apart from it, or the bubble will seem to dissolve into the page.

When to use something else

CSS tooltips are good for short labels on icons and for brief explanations of a term. They are the wrong tool when the content has links or buttons inside, because the tip disappears when the pointer leaves the element, so the visitor cannot move into it. For richer content, use a popover that opens on click.

Also consider the native title attribute for the simplest cases. It needs no CSS and works with assistive technology, though you cannot style it and it appears after a delay. A custom tooltip is the right choice when you want a consistent look, an arrow or an immediate response.

Tips

  • Choose hover and focus unless you have a reason not to. It adds tabindex so keyboard users can reach the element and see the tip, which hover alone never offers them.
  • Do not put anything essential in a tooltip. Phones and tablets have no hover, and text drawn by CSS may not be read aloud by assistive technology. Use it for hints, and put real instructions in the page.
  • Mind the edges. A tooltip on the left side of the screen set to appear on the left will be cut off. Pick the side with room, or give the trigger some margin.
  • Keep the text short, one line if you can. When it must be longer, set a maximum width so the bubble wraps instead of stretching across the page.

Frequently asked questions

How does a pure CSS tooltip work?

The tip text is stored in a data-tooltip attribute on the element. The ::after pseudo-element shows that text with content: attr(data-tooltip) and is positioned next to the element. The ::before pseudo-element draws the arrow with a CSS border triangle. Both are hidden until the element is hovered or focused.

How is the arrow made?

A box with no width or height and a thick border looks like four triangles meeting in the middle. Making three of the borders transparent leaves one coloured triangle. For a tooltip above the element, the arrow has a coloured top border and transparent left and right borders, so it points downwards.

What do the gap and arrow size do?

The arrow size is the height of the triangle. The gap is the empty space between the element and the arrow tip. The bubble sits at gap plus arrow size from the element, so with a 4 pixel gap and a 6 pixel arrow, the bubble starts 10 pixels away.

Is this accessible?

It works for mouse and, with the focus option, for keyboard users. Screen readers may not announce text drawn by CSS, so if the information matters, also give the element an aria-label or put the text on the page. Tooltips are also unavailable on touch screens.

Can I use more than one tooltip on a page?

Yes. The CSS is attached to a class, so add that class and a different data-tooltip to as many elements as you like. Use the class name box if tooltip clashes with a class already in your stylesheet.

Related: CSS shadow generator, CSS layout generator, Color contrast checker.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Free Tools

Product

Who It's For

Features

Resources

Company

View Sitemap