Animated CSS Tooltip

Tooltips that fade and rise from the control, including a downward variant, using only CSS and a data attribute.


Animated CSS Tooltip


An animated CSS tooltip is the small label that appears when someone points at a control: a fade plus a few pixels of travel, so it feels placed rather than popped. The pattern is searched constantly because the native title attribute is slow, unstyled, and invisible on touch. A data-tip attribute and two pseudo-elements cover the styled case without a library.

The demo shows four actions. Share and Save open upward. Preview and Export open downward, for controls that sit near the top of a panel. One tooltip starts visible so the motion is obvious before you hover. Focus shows the same bubble as hover, which is the part people forget.

This is a cousin of the contextual label cursor, which follows the pointer. A tooltip is anchored to the control.

Markup

<button class="tip" type="button" data-tip="Copies the public link">Share</button>
<button class="tip down" type="button" data-tip="Opens the preview">Preview</button>

The button’s text is the accessible name. The tooltip repeats a clarification. Do not put the only instruction in data-tip, because a pseudo-element is not reliably exposed to assistive technology. If the bubble holds essential text, use a real element toggled with aria-describedby.

The bubble and the caret

.tip { position: relative; }
.tip::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%) translateY(6px);
  opacity: 0;
  background: #111;
  color: #fff;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  white-space: nowrap;
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.tip::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 4px);
  border: 6px solid transparent;
  border-top-color: #111;
  transform: translateX(-50%) translateY(6px);
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
}
.tip:hover::after, .tip:focus-visible::after,
.tip:hover::before, .tip:focus-visible::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

pointer-events: none keeps the bubble from stealing the hover as you move toward it, which is the usual cause of a flickering tooltip. white-space: nowrap is right for a short phrase. A sentence needs a real element with a max-width, because a nowrap bubble will leave the viewport.

The downward variant moves top instead of bottom and flips the caret border from border-top-color to border-bottom-color. The travel starts at translateY(-6px) so it still moves away from the button as it appears.

Timing

200ms is the whole animation. Longer than that and the tooltip feels late for a label that should already have been obvious. The rise is 6px. More travel reads as a dropdown, not a hint.

Questions about CSS tooltips

How do I animate a tooltip with CSS only?

Put the label in a data-tip attribute, render it with ::after and content: attr(data-tip), and transition opacity plus a short translate. Show it on :hover and :focus-visible.

Why does my tooltip flicker?

The bubble is under the pointer, so hover ends when you reach it, which hides it, which restores hover. Set pointer-events: none on the pseudo-elements.

Are CSS tooltips accessible?

They are a visual hint. The control still needs a real accessible name. Add :focus-visible so keyboard users see the same bubble. For text someone must hear, use a real node referenced with aria-describedby.