# Pure CSS Tooltip

> A tooltip that reads its text from a data attribute and fades in on hover.

- Category: [CSS Effects](https://copy-css.com/category/effects)
- Tags: tooltip, hover, attr, popover
- Live preview: https://copy-css.com/snippets/css-tooltip
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<button class="tooltip" data-tip="Copied to clipboard!">Hover me</button>
```

## CSS

```css
.tooltip {
  position: relative;
  padding: 10px 18px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  font: 500 15px system-ui, sans-serif;
  cursor: pointer;
}

.tooltip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  padding: 6px 10px;
  border-radius: 6px;
  background: #111827;
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.tooltip:hover::after,
.tooltip:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}
```

## Notes

- This CSS Tooltip is 32 lines of pure CSS (0.6 KB) with no JavaScript and no dependencies. It uses transitions, transforms and keyboard focus styles.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
