StealThis .dev

Tooltip with Arrow Variants

CSS-only tooltips with four directional arrow variants (top, right, bottom, left). Triggered on hover and focus, with smooth fade-in and accessible markup.

Open in Lab
css pseudo-elements css-variables
Targets: HTML

Code

Tooltip with Arrow Variants

Pure CSS tooltips in four directions — top, right, bottom, left — using ::before (arrow) and ::after (bubble) pseudo-elements on the trigger element. No JavaScript required.

How it works

Each tooltip trigger carries a data-tooltip attribute for the text and a positional class (tooltip--top, tooltip--right, etc.):

<button class="tooltip--top" data-tooltip="Saved!" aria-describedby="tip-1">
  Save
</button>

The pseudo-elements are position: absolute, positioned relative to the trigger’s position: relative wrapper. Visibility toggles on :hover and :focus-visible.

Arrow technique

A zero-size ::before with border tricks creates the directional arrow:

.tooltip--top::before {
  border: 6px solid transparent;
  border-top-color: var(--tooltip-bg);
}

When to use it

  • Icon buttons that need labels
  • Form field hints
  • Table cell explanations