Cards · episode 01 · Beginner
Animated Glassmorphism Profile Card
A frosted-glass profile card with a 3D pointer tilt, moving glare, animated avatar ring, counting stats and a follow button with a ripple — in plain HTML, CSS and JavaScript.
- glassmorphism
- profile card
- backdrop-filter
- 3d tilt
- css animation
- vanilla javascript
- responsive
- MIT
// Source code
Three files, no dependencies. MIT licensed — use it anywhere.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Glassmorphism Profile Card</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="backdrop" aria-hidden="true">
<span class="blob blob--lime"></span>
<span class="blob blob--teal"></span>
<span class="blob blob--violet"></span>
</div>
<main class="scene">
<article class="card" aria-labelledby="card-name">
<div class="card__glare" aria-hidden="true"></div>
<header class="card__header">
<div class="avatar">
<svg class="avatar__img" viewBox="0 0 96 96" role="img" aria-label="Avatar of Nova Reyes">
<defs>
<linearGradient id="avatar-bg" x1="0" y1="0" x2="1" y2="1">
<stop offset="0" stop-color="#a3e635" />
<stop offset="1" stop-color="#2dd4bf" />
</linearGradient>
</defs>
<rect width="96" height="96" fill="url(#avatar-bg)" />
<circle cx="48" cy="40" r="17" fill="#14171f" />
<path d="M16 96c4-20 17-30 32-30s28 10 32 30z" fill="#14171f" />
</svg>
<span class="avatar__status" role="img" aria-label="Available for work"></span>
</div>
<h1 class="card__name" id="card-name">Nova Reyes</h1>
<p class="card__role">Creative Developer</p>
</header>
<p class="card__bio">
Building playful interfaces with careful motion and accessible markup.
</p>
<ul class="stats">
<li class="stats__item">
<span class="stats__value" data-count="48">48</span>
<span class="stats__label">Projects</span>
</li>
<li class="stats__item">
<span class="stats__value" data-count="1284" data-stat="followers">1,284</span>
<span class="stats__label">Followers</span>
</li>
<li class="stats__item">
<span class="stats__value" data-count="3917">3,917</span>
<span class="stats__label">Commits</span>
</li>
</ul>
<ul class="tags" aria-label="Skills">
<li class="tag">HTML</li>
<li class="tag">CSS</li>
<li class="tag">JavaScript</li>
<li class="tag">Motion</li>
</ul>
<div class="card__actions">
<button class="btn btn--primary" type="button" data-follow>
<span class="btn__label">Follow</span>
</button>
<a class="btn btn--ghost" href="mailto:[email protected]">Message</a>
</div>
<nav class="socials" aria-label="Social links">
<a class="socials__link" href="https://example.com" aria-label="Website">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true">
<circle cx="12" cy="12" r="9" />
<path d="M3 12h18M12 3c2.5 2.7 3.8 5.7 3.8 9s-1.3 6.3-3.8 9c-2.5-2.7-3.8-5.7-3.8-9S9.5 5.7 12 3z" />
</svg>
</a>
<a class="socials__link" href="mailto:[email protected]" aria-label="Email">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<rect x="3" y="5" width="18" height="14" rx="2" />
<path d="m3 7 9 6 9-6" />
</svg>
</a>
<a class="socials__link" href="https://example.com/code" aria-label="Code portfolio">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="m8 7-5 5 5 5M16 7l5 5-5 5M14 4l-4 16" />
</svg>
</a>
</nav>
</article>
</main>
<script src="script.js"></script>
</body>
</html>/* ===== Reset & tokens ===== */
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
}
:root {
--bg: #0d0f14;
--text: #f8fafc;
--muted: #c3c7d1;
--accent: #a3e635;
--glass: rgb(255 255 255 / 0.08);
--glass-border: rgb(255 255 255 / 0.18);
--radius: 28px;
}
body {
min-height: 100vh;
min-height: 100dvh;
display: grid;
place-items: center;
padding: 2rem 1rem;
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
color: var(--text);
background: var(--bg);
overflow-x: hidden;
}
/* ===== Animated background ===== */
.backdrop {
position: fixed;
inset: 0;
z-index: -1;
overflow: hidden;
}
.blob {
position: absolute;
width: 42vmax;
aspect-ratio: 1;
border-radius: 50%;
filter: blur(70px);
opacity: 0.5;
animation: drift 18s ease-in-out infinite alternate;
}
.blob--lime {
--dx: 12vmax;
--dy: 8vmax;
top: -14%;
left: -10%;
background: #a3e635;
}
.blob--teal {
--dx: -14vmax;
--dy: -6vmax;
right: -12%;
bottom: -20%;
background: #2dd4bf;
animation-delay: -6s;
}
.blob--violet {
--dx: -10vmax;
--dy: 10vmax;
top: 30%;
left: 50%;
width: 30vmax;
background: #8b5cf6;
animation-delay: -12s;
}
@keyframes drift {
to {
transform: translate(var(--dx), var(--dy)) scale(1.15);
}
}
/* ===== Glass card ===== */
.scene {
width: 100%;
display: grid;
place-items: center;
perspective: 1000px;
}
.card {
--rx: 0deg;
--ry: 0deg;
--mx: 50%;
--my: 50%;
position: relative;
width: min(100%, 360px);
padding: 2rem 1.75rem 1.75rem;
border-radius: var(--radius);
text-align: center;
background: linear-gradient(135deg, rgb(255 255 255 / 0.12), rgb(255 255 255 / 0.03)), rgb(13 15 20 / 0.45);
border: 1px solid var(--glass-border);
backdrop-filter: blur(20px) saturate(160%);
-webkit-backdrop-filter: blur(20px) saturate(160%);
box-shadow:
0 24px 60px rgb(0 0 0 / 0.45),
inset 0 1px 0 rgb(255 255 255 / 0.25);
transform: rotateX(var(--rx)) rotateY(var(--ry));
transition: transform 0.25s ease-out;
animation: card-in 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes card-in {
from {
opacity: 0;
translate: 0 40px;
scale: 0.96;
}
}
.card__glare {
position: absolute;
inset: 0;
border-radius: inherit;
background: radial-gradient(circle at var(--mx) var(--my), rgb(255 255 255 / 0.22), transparent 45%);
opacity: 0;
transition: opacity 0.3s ease;
pointer-events: none;
}
.card:hover .card__glare {
opacity: 1;
}
/* ===== Avatar ===== */
.avatar {
position: relative;
width: 104px;
aspect-ratio: 1;
margin: 0 auto 1rem;
padding: 4px;
border-radius: 50%;
}
.avatar::before {
content: "";
position: absolute;
inset: 0;
border-radius: 50%;
background: conic-gradient(#a3e635, #2dd4bf, #8b5cf6, #a3e635);
animation: spin 6s linear infinite;
}
.avatar__img {
position: relative;
display: block;
width: 100%;
height: 100%;
border-radius: 50%;
border: 3px solid var(--bg);
}
.avatar__status {
position: absolute;
right: 8px;
bottom: 8px;
width: 16px;
height: 16px;
border-radius: 50%;
background: var(--accent);
border: 3px solid var(--bg);
animation: pulse 2s ease-out infinite;
}
@keyframes spin {
to {
rotate: 1turn;
}
}
@keyframes pulse {
0% {
box-shadow: 0 0 0 0 rgb(163 230 53 / 0.6);
}
70%,
100% {
box-shadow: 0 0 0 10px rgb(163 230 53 / 0);
}
}
/* ===== Text ===== */
.card__name {
font-size: 1.5rem;
font-weight: 700;
letter-spacing: -0.02em;
}
.card__role {
margin-top: 0.25rem;
color: var(--accent);
font-size: 0.8rem;
font-weight: 600;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.card__bio {
max-width: 30ch;
margin: 1rem auto 0;
color: var(--muted);
font-size: 0.95rem;
line-height: 1.6;
}
/* ===== Stats ===== */
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
margin: 1.5rem 0;
padding: 1rem 0;
list-style: none;
border-block: 1px solid var(--glass-border);
}
.stats__item {
display: grid;
gap: 0.15rem;
}
.stats__item + .stats__item {
border-left: 1px solid var(--glass-border);
}
.stats__value {
font-size: 1.25rem;
font-weight: 700;
font-variant-numeric: tabular-nums;
}
.stats__label {
color: var(--muted);
font-size: 0.7rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
/* ===== Tags ===== */
.tags {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 0.5rem;
padding: 0;
list-style: none;
}
.tag {
padding: 0.35rem 0.8rem;
border-radius: 999px;
font-size: 0.8rem;
background: var(--glass);
border: 1px solid var(--glass-border);
transition: background 0.2s, border-color 0.2s, translate 0.2s;
}
.tag:hover {
background: rgb(163 230 53 / 0.15);
border-color: rgb(163 230 53 / 0.5);
translate: 0 -2px;
}
/* ===== Buttons ===== */
.card__actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.75rem;
margin-top: 1.5rem;
}
.btn {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0.8rem 1rem;
border: 1px solid transparent;
border-radius: 14px;
font: inherit;
font-size: 0.9rem;
font-weight: 600;
text-decoration: none;
cursor: pointer;
overflow: hidden;
transition: scale 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.btn:active {
scale: 0.96;
}
.btn--primary {
color: #111318;
background: var(--accent);
box-shadow: 0 8px 24px rgb(163 230 53 / 0.35);
}
.btn--primary:hover {
box-shadow: 0 10px 32px rgb(163 230 53 / 0.55);
}
.btn--primary[data-following="true"] {
color: var(--accent);
background: transparent;
border-color: var(--accent);
box-shadow: none;
}
.btn--ghost {
color: var(--text);
background: var(--glass);
border-color: var(--glass-border);
}
.btn--ghost:hover {
background: rgb(255 255 255 / 0.16);
}
.ripple {
position: absolute;
width: 12px;
aspect-ratio: 1;
border-radius: 50%;
background: currentColor;
opacity: 0.35;
translate: -50% -50%;
pointer-events: none;
animation: ripple 0.6s ease-out forwards;
}
@keyframes ripple {
to {
scale: 30;
opacity: 0;
}
}
/* ===== Social links ===== */
.socials {
display: flex;
justify-content: center;
gap: 0.75rem;
margin-top: 1.25rem;
}
.socials__link {
display: grid;
place-items: center;
width: 44px;
height: 44px;
border-radius: 12px;
color: var(--muted);
background: var(--glass);
border: 1px solid var(--glass-border);
transition: color 0.2s, background 0.2s, translate 0.2s;
}
.socials__link:hover {
color: #111318;
background: var(--accent);
translate: 0 -3px;
}
.socials__link svg {
width: 20px;
height: 20px;
}
.btn:focus-visible,
.socials__link:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
/* ===== Responsive & motion ===== */
@media (max-width: 400px) {
.card {
padding: 1.75rem 1.25rem 1.5rem;
}
.avatar {
width: 88px;
}
.card__actions {
gap: 0.5rem;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}// ===== 3D tilt & glare =====
const card = document.querySelector(".card");
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
const MAX_TILT = 8;
card.addEventListener("pointermove", (event) => {
if (reduceMotion.matches || event.pointerType === "touch") return;
const rect = card.getBoundingClientRect();
const x = (event.clientX - rect.left) / rect.width;
const y = (event.clientY - rect.top) / rect.height;
card.style.setProperty("--ry", `${(x - 0.5) * MAX_TILT * 2}deg`);
card.style.setProperty("--rx", `${(0.5 - y) * MAX_TILT * 2}deg`);
card.style.setProperty("--mx", `${x * 100}%`);
card.style.setProperty("--my", `${y * 100}%`);
});
card.addEventListener("pointerleave", () => {
card.style.setProperty("--rx", "0deg");
card.style.setProperty("--ry", "0deg");
});
// ===== Counting stats =====
const formatNumber = new Intl.NumberFormat("en").format;
function countUp(element) {
const target = Number(element.dataset.count);
const duration = 1400;
const start = performance.now();
function tick(now) {
const progress = Math.min((now - start) / duration, 1);
const eased = 1 - Math.pow(1 - progress, 3);
element.textContent = formatNumber(Math.round(target * eased));
if (progress < 1) requestAnimationFrame(tick);
}
requestAnimationFrame(tick);
}
document.querySelectorAll("[data-count]").forEach((element) => {
if (reduceMotion.matches) return;
countUp(element);
});
// ===== Follow button & ripple =====
const followButton = document.querySelector("[data-follow]");
const followLabel = followButton.querySelector(".btn__label");
const followers = document.querySelector('[data-stat="followers"]');
followButton.addEventListener("click", (event) => {
const following = followButton.dataset.following === "true";
followButton.dataset.following = String(!following);
followLabel.textContent = following ? "Follow" : "Following";
const count = Number(followers.dataset.count) + (following ? -1 : 1);
followers.dataset.count = count;
followers.textContent = formatNumber(count);
addRipple(followButton, event);
});
function addRipple(button, event) {
const rect = button.getBoundingClientRect();
const isKeyboard = event.detail === 0;
const ripple = document.createElement("span");
ripple.className = "ripple";
ripple.style.left = `${isKeyboard ? rect.width / 2 : event.clientX - rect.left}px`;
ripple.style.top = `${isKeyboard ? rect.height / 2 : event.clientY - rect.top}px`;
button.append(ripple);
ripple.addEventListener("animationend", () => ripple.remove());
}// Step by step
The same 14 steps the video follows. Each block is the exact code added in that step.
01 HTML boilerplate Start with a plain HTML document. It links the stylesheet and script, and adds a decorative backdrop with three blurred colour blobs. The
aria-hiddenattribute keeps the decoration away from screen readers.index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Glassmorphism Profile Card</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="backdrop" aria-hidden="true"> <span class="blob blob--lime"></span> <span class="blob blob--teal"></span> <span class="blob blob--violet"></span> </div> <main class="scene"> </main> <script src="script.js"></script> </body> </html>02 Card header and avatar The card is an
articlelabelled by its heading. The avatar is an inline SVG illustration, so the card works offline with no image requests. A small status dot sits on top of it.index.html
<article class="card" aria-labelledby="card-name"> <div class="card__glare" aria-hidden="true"></div> <header class="card__header"> <div class="avatar"> <svg class="avatar__img" viewBox="0 0 96 96" role="img" aria-label="Avatar of Nova Reyes"> <defs> <linearGradient id="avatar-bg" x1="0" y1="0" x2="1" y2="1"> <stop offset="0" stop-color="#a3e635" /> <stop offset="1" stop-color="#2dd4bf" /> </linearGradient> </defs> <rect width="96" height="96" fill="url(#avatar-bg)" /> <circle cx="48" cy="40" r="17" fill="#14171f" /> <path d="M16 96c4-20 17-30 32-30s28 10 32 30z" fill="#14171f" /> </svg> <span class="avatar__status" role="img" aria-label="Available for work"></span> </div> <h1 class="card__name" id="card-name">Nova Reyes</h1> <p class="card__role">Creative Developer</p> </header> </article>03 Bio, stats and skills Add a short bio, three stats and a list of skill tags. Each stat keeps its real value in the markup and in a
data-countattribute, which the counter animation reads later.index.html
<p class="card__bio"> Building playful interfaces with careful motion and accessible markup. </p> <ul class="stats"> <li class="stats__item"> <span class="stats__value" data-count="48">48</span> <span class="stats__label">Projects</span> </li> <li class="stats__item"> <span class="stats__value" data-count="1284" data-stat="followers">1,284</span> <span class="stats__label">Followers</span> </li> <li class="stats__item"> <span class="stats__value" data-count="3917">3,917</span> <span class="stats__label">Commits</span> </li> </ul> <ul class="tags" aria-label="Skills"> <li class="tag">HTML</li> <li class="tag">CSS</li> <li class="tag">JavaScript</li> <li class="tag">Motion</li> </ul>04 Actions and social links Finish the markup with a follow button, a message link and three icon links. Icon-only links get an
aria-labelso they still have an accessible name.index.html
<div class="card__actions"> <button class="btn btn--primary" type="button" data-follow> <span class="btn__label">Follow</span> </button> <a class="btn btn--ghost" href="mailto:[email protected]">Message</a> </div> <nav class="socials" aria-label="Social links"> <a class="socials__link" href="https://example.com" aria-label="Website"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"> <circle cx="12" cy="12" r="9" /> <path d="M3 12h18M12 3c2.5 2.7 3.8 5.7 3.8 9s-1.3 6.3-3.8 9c-2.5-2.7-3.8-5.7-3.8-9S9.5 5.7 12 3z" /> </svg> </a> <a class="socials__link" href="mailto:[email protected]" aria-label="Email"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <rect x="3" y="5" width="18" height="14" rx="2" /> <path d="m3 7 9 6 9-6" /> </svg> </a> <a class="socials__link" href="https://example.com/code" aria-label="Code portfolio"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="m8 7-5 5 5 5M16 7l5 5-5 5M14 4l-4 16" /> </svg> </a> </nav>05 Reset and design tokens Now the CSS. A small reset, then custom properties for colours and radius, so the whole card can be re-themed from one place. The body centres its content with a one-line grid.
style.css
/* ===== Reset & tokens ===== */ *, *::before, *::after { box-sizing: border-box; margin: 0; } :root { --bg: #0d0f14; --text: #f8fafc; --muted: #c3c7d1; --accent: #a3e635; --glass: rgb(255 255 255 / 0.08); --glass-border: rgb(255 255 255 / 0.18); --radius: 28px; } body { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 2rem 1rem; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); overflow-x: hidden; }06 Animated background Glass only looks like glass when there is something colourful behind it. Each blob is a heavily blurred circle that drifts in its own direction, set through
--dxand--dy. Negative delays start the blobs at different points in the loop.style.css
/* ===== Animated background ===== */ .backdrop { position: fixed; inset: 0; z-index: -1; overflow: hidden; } .blob { position: absolute; width: 42vmax; aspect-ratio: 1; border-radius: 50%; filter: blur(70px); opacity: 0.5; animation: drift 18s ease-in-out infinite alternate; } .blob--lime { --dx: 12vmax; --dy: 8vmax; top: -14%; left: -10%; background: #a3e635; } .blob--teal { --dx: -14vmax; --dy: -6vmax; right: -12%; bottom: -20%; background: #2dd4bf; animation-delay: -6s; } .blob--violet { --dx: -10vmax; --dy: 10vmax; top: 30%; left: 50%; width: 30vmax; background: #8b5cf6; animation-delay: -12s; } @keyframes drift { to { transform: translate(var(--dx), var(--dy)) scale(1.15); } }07 Frosted glass card The glass effect is three things: a translucent background, a thin light border and
backdrop-filter, which blurs whatever is behind the card. The tilt angles and glare position are custom properties that JavaScript will update. The entrance animation usestranslateandscale, so it never fights the tilttransform.style.css
/* ===== Glass card ===== */ .scene { width: 100%; display: grid; place-items: center; perspective: 1000px; } .card { --rx: 0deg; --ry: 0deg; --mx: 50%; --my: 50%; position: relative; width: min(100%, 360px); padding: 2rem 1.75rem 1.75rem; border-radius: var(--radius); text-align: center; background: linear-gradient(135deg, rgb(255 255 255 / 0.12), rgb(255 255 255 / 0.03)), rgb(13 15 20 / 0.45); border: 1px solid var(--glass-border); backdrop-filter: blur(20px) saturate(160%); -webkit-backdrop-filter: blur(20px) saturate(160%); box-shadow: 0 24px 60px rgb(0 0 0 / 0.45), inset 0 1px 0 rgb(255 255 255 / 0.25); transform: rotateX(var(--rx)) rotateY(var(--ry)); transition: transform 0.25s ease-out; animation: card-in 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) both; } @keyframes card-in { from { opacity: 0; translate: 0 40px; scale: 0.96; } } .card__glare { position: absolute; inset: 0; border-radius: inherit; background: radial-gradient(circle at var(--mx) var(--my), rgb(255 255 255 / 0.22), transparent 45%); opacity: 0; transition: opacity 0.3s ease; pointer-events: none; } .card:hover .card__glare { opacity: 1; }08 Avatar ring A spinning
conic-gradientbehind the avatar becomes a colourful ring, because the avatar is 4px smaller than its wrapper. The status dot pulses with an expandingbox-shadow.style.css
/* ===== Avatar ===== */ .avatar { position: relative; width: 104px; aspect-ratio: 1; margin: 0 auto 1rem; padding: 4px; border-radius: 50%; } .avatar::before { content: ""; position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(#a3e635, #2dd4bf, #8b5cf6, #a3e635); animation: spin 6s linear infinite; } .avatar__img { position: relative; display: block; width: 100%; height: 100%; border-radius: 50%; border: 3px solid var(--bg); } .avatar__status { position: absolute; right: 8px; bottom: 8px; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg); animation: pulse 2s ease-out infinite; } @keyframes spin { to { rotate: 1turn; } } @keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(163 230 53 / 0.6); } 70%, 100% { box-shadow: 0 0 0 10px rgb(163 230 53 / 0); } }09 Text, stats and tags Typography stays simple: a bold name, an uppercase accent role and a muted bio. The stats use a three-column grid with
tabular-nums, so digits do not jump while they count. Tags lift slightly on hover.style.css
/* ===== Text ===== */ .card__name { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; } .card__role { margin-top: 0.25rem; color: var(--accent); font-size: 0.8rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; } .card__bio { max-width: 30ch; margin: 1rem auto 0; color: var(--muted); font-size: 0.95rem; line-height: 1.6; } /* ===== Stats ===== */ .stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 1.5rem 0; padding: 1rem 0; list-style: none; border-block: 1px solid var(--glass-border); } .stats__item { display: grid; gap: 0.15rem; } .stats__item + .stats__item { border-left: 1px solid var(--glass-border); } .stats__value { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; } .stats__label { color: var(--muted); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; } /* ===== Tags ===== */ .tags { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; padding: 0; list-style: none; } .tag { padding: 0.35rem 0.8rem; border-radius: 999px; font-size: 0.8rem; background: var(--glass); border: 1px solid var(--glass-border); transition: background 0.2s, border-color 0.2s, translate 0.2s; } .tag:hover { background: rgb(163 230 53 / 0.15); border-color: rgb(163 230 53 / 0.5); translate: 0 -2px; }10 Buttons and social links Both buttons share one
.btnbase. The primary button glows, and its "following" state swaps to an outline.overflow: hiddenclips the ripple that JavaScript adds on click. Every interactive element gets a clear:focus-visibleoutline for keyboard users.style.css
/* ===== Buttons ===== */ .card__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-top: 1.5rem; } .btn { position: relative; display: inline-flex; align-items: center; justify-content: center; padding: 0.8rem 1rem; border: 1px solid transparent; border-radius: 14px; font: inherit; font-size: 0.9rem; font-weight: 600; text-decoration: none; cursor: pointer; overflow: hidden; transition: scale 0.2s ease, background 0.2s ease, box-shadow 0.2s ease; } .btn:active { scale: 0.96; } .btn--primary { color: #111318; background: var(--accent); box-shadow: 0 8px 24px rgb(163 230 53 / 0.35); } .btn--primary:hover { box-shadow: 0 10px 32px rgb(163 230 53 / 0.55); } .btn--primary[data-following="true"] { color: var(--accent); background: transparent; border-color: var(--accent); box-shadow: none; } .btn--ghost { color: var(--text); background: var(--glass); border-color: var(--glass-border); } .btn--ghost:hover { background: rgb(255 255 255 / 0.16); } .ripple { position: absolute; width: 12px; aspect-ratio: 1; border-radius: 50%; background: currentColor; opacity: 0.35; translate: -50% -50%; pointer-events: none; animation: ripple 0.6s ease-out forwards; } @keyframes ripple { to { scale: 30; opacity: 0; } } /* ===== Social links ===== */ .socials { display: flex; justify-content: center; gap: 0.75rem; margin-top: 1.25rem; } .socials__link { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; color: var(--muted); background: var(--glass); border: 1px solid var(--glass-border); transition: color 0.2s, background 0.2s, translate 0.2s; } .socials__link:hover { color: #111318; background: var(--accent); translate: 0 -3px; } .socials__link svg { width: 20px; height: 20px; } .btn:focus-visible, .socials__link:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }11 3D tilt and glare The tilt reads the pointer position inside the card as a value from 0 to 1 on each axis. That value drives the rotation and the glare position through the custom properties from the CSS. Touch input and reduced-motion users get a still card.
script.js
// ===== 3D tilt & glare ===== const card = document.querySelector(".card"); const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)"); const MAX_TILT = 8; card.addEventListener("pointermove", (event) => { if (reduceMotion.matches || event.pointerType === "touch") return; const rect = card.getBoundingClientRect(); const x = (event.clientX - rect.left) / rect.width; const y = (event.clientY - rect.top) / rect.height; card.style.setProperty("--ry", `${(x - 0.5) * MAX_TILT * 2}deg`); card.style.setProperty("--rx", `${(0.5 - y) * MAX_TILT * 2}deg`); card.style.setProperty("--mx", `${x * 100}%`); card.style.setProperty("--my", `${y * 100}%`); }); card.addEventListener("pointerleave", () => { card.style.setProperty("--rx", "0deg"); card.style.setProperty("--ry", "0deg"); });12 Counting stats Each stat counts up from zero with an ease-out curve driven by
requestAnimationFrame.Intl.NumberFormatadds the thousands separator. With reduced motion, the final number is shown straight away.script.js
// ===== Counting stats ===== const formatNumber = new Intl.NumberFormat("en").format; function countUp(element) { const target = Number(element.dataset.count); const duration = 1400; const start = performance.now(); function tick(now) { const progress = Math.min((now - start) / duration, 1); const eased = 1 - Math.pow(1 - progress, 3); element.textContent = formatNumber(Math.round(target * eased)); if (progress < 1) requestAnimationFrame(tick); } requestAnimationFrame(tick); } document.querySelectorAll("[data-count]").forEach((element) => { if (reduceMotion.matches) return; countUp(element); });13 Follow button with ripple Clicking follow flips a
data-followingattribute, which the CSS styles, updates the label and adjusts the follower count. The ripple starts where the pointer clicked, or in the centre for keyboard clicks, and removes itself when its animation ends.script.js
// ===== Follow button & ripple ===== const followButton = document.querySelector("[data-follow]"); const followLabel = followButton.querySelector(".btn__label"); const followers = document.querySelector('[data-stat="followers"]'); followButton.addEventListener("click", (event) => { const following = followButton.dataset.following === "true"; followButton.dataset.following = String(!following); followLabel.textContent = following ? "Follow" : "Following"; const count = Number(followers.dataset.count) + (following ? -1 : 1); followers.dataset.count = count; followers.textContent = formatNumber(count); addRipple(followButton, event); }); function addRipple(button, event) { const rect = button.getBoundingClientRect(); const isKeyboard = event.detail === 0; const ripple = document.createElement("span"); ripple.className = "ripple"; ripple.style.left = `${isKeyboard ? rect.width / 2 : event.clientX - rect.left}px`; ripple.style.top = `${isKeyboard ? rect.height / 2 : event.clientY - rect.top}px`; button.append(ripple); ripple.addEventListener("animationend", () => ripple.remove()); }14 Responsive and reduced motion On narrow screens, the card trims its padding and the avatar shrinks. Finally,
prefers-reduced-motionturns the animations off for people who ask their system for less motion.style.css
/* ===== Responsive & motion ===== */ @media (max-width: 400px) { .card { padding: 1.75rem 1.25rem 1.5rem; } .avatar { width: 88px; } .card__actions { gap: 0.5rem; } } @media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; } }