CSS 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.
Thanks to @mira Mira Okafor Design engineer. Builds tiny tools. for the review.
<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>
.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;
}
}
About this CSS User Hover Card
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. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
Customize it
The colors in this snippet. Search and replace them to match your brand:
#44403c#7c3aed#e7e5e4#fff#57534e#a78bfa#6d28d9#1c1917
How to use this user hover card
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.mention-textclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.