# User Hover Card

> A rich tooltip that previews a user profile when you hover or tab to an @mention, and stays open while you use it.

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

## HTML

```html
<p class="mention-text">
  Thanks to
  <span class="hover-card">
    <a href="#" aria-describedby="hover-card-mira">@mira</a>
    <span class="hover-card-panel" id="hover-card-mira" role="tooltip">
      <span class="hover-card-avatar" aria-hidden="true">MO</span>
      <strong>Mira Okafor</strong>
      <span>Design engineer. Builds tiny tools.</span>
    </span>
  </span>
  for the review.
</p>
```

## CSS

```css
.mention-text {
  max-width: 260px;
  margin: 0;
  color: #44403c;
  font: 16px/1.6 system-ui, sans-serif;
}

.hover-card {
  position: relative;
  display: inline-block;
}

.hover-card > a {
  color: #7c3aed;
  font-weight: 700;
  text-decoration: none;
}

.hover-card > a:focus-visible {
  outline: 2px solid #7c3aed;
  outline-offset: 2px;
  border-radius: 3px;
}

.hover-card-panel {
  position: absolute;
  top: 100%;
  left: 50%;
  z-index: 10;
  display: grid;
  gap: 2px;
  width: 200px;
  margin-top: 8px;
  padding: 14px;
  border: 1px solid #e7e5e4;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 16px 32px -12px rgba(28, 25, 23, 0.3);
  color: #57534e;
  font-size: 13px;
  line-height: 1.4;
  opacity: 0;
  visibility: hidden;
  translate: -50% 6px;
  transition: opacity 0.2s ease, translate 0.2s ease, visibility 0.2s;
}

.hover-card-panel::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  height: 10px;
}

.hover-card:hover .hover-card-panel,
.hover-card:focus-within .hover-card-panel {
  opacity: 1;
  visibility: visible;
  translate: -50% 0;
}

.hover-card-avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-bottom: 6px;
  border-radius: 50%;
  background: linear-gradient(135deg, #a78bfa, #6d28d9);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.hover-card-panel strong {
  color: #1c1917;
  font-size: 15px;
}

@media (prefers-reduced-motion: reduce) {
  .hover-card-panel {
    transition: none;
  }
}
```

## Notes

- This CSS User Hover Card is 86 lines of pure CSS (1.5 KB) with no JavaScript and no dependencies. It uses transitions, linear gradients, box shadows and CSS Grid.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
