Kinetic Avatar
A person or team picture that falls back to colored initials, with four sizes, two shapes and a presence dot.
- <kt-kinetic-avatar>
- Display
- No framework
The code
Copy the Kinetic Avatar
Fastest: press Copy on the card above for one complete file. To build it into your own
project, use the files below: the markup, the styles, this component’s script and the shared
effects script (effects.js) that every component uses.
<kt-kinetic-avatar name="Mara Okafor" size="lg" status="online"></kt-kinetic-avatar>
<kt-kinetic-avatar name="Jonas Weber" size="lg" shape="square" status="away" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 80'%3E%3Cdefs%3E%3ClinearGradient id='g' x1='0' y1='0' x2='1' y2='1'%3E%3Cstop offset='0' stop-color='%23f59e0b'/%3E%3Cstop offset='1' stop-color='%23be123c'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='80' height='80' fill='url(%23g)'/%3E%3Ccircle cx='40' cy='32' r='14' fill='%23fff' fill-opacity='.88'/%3E%3Cpath d='M12 80c4-18 16-26 28-26s24 8 28 26z' fill='%23fff' fill-opacity='.88'/%3E%3C/svg%3E"></kt-kinetic-avatar>
<kt-kinetic-avatar name="Priya Raman" size="md" status="busy"></kt-kinetic-avatar>
<kt-kinetic-avatar name="Design Team" size="sm" shape="square"></kt-kinetic-avatar>
<span style="display:inline-flex;align-items:center;padding-left:2px"><kt-kinetic-avatar name="Ana Silva" size="md"></kt-kinetic-avatar><kt-kinetic-avatar name="Ben Carter" size="md" style="margin-left:-10px"></kt-kinetic-avatar><kt-kinetic-avatar name="Chloe Dubois" size="md" style="margin-left:-10px"></kt-kinetic-avatar><kt-kinetic-avatar name="Dev Patel" size="md" style="margin-left:-10px"></kt-kinetic-avatar></span>
kt-kinetic-avatar {
display: inline-block;
vertical-align: middle;
line-height: 0;
}
.kt-avatar {
--_s: 40px;
--_bg: #1d4ed8;
--_ring: var(--kt-surface-bg);
position: relative;
display: inline-block;
width: var(--_s);
height: var(--_s);
flex-shrink: 0;
font-family: var(--font-sans);
}
.kt-avatar[data-size="sm"] { --_s: 28px; }
.kt-avatar[data-size="lg"] { --_s: 56px; }
.kt-avatar[data-size="xl"] { --_s: 80px; }
.kt-avatar-face {
position: absolute;
inset: 0;
display: grid;
place-items: center;
overflow: hidden;
border-radius: 50%;
background: var(--_bg);
color: #ffffff;
box-shadow: 0 0 0 2px var(--_ring), var(--kt-comp-shadow, 0 0 #0000);
transition: transform 180ms ease, box-shadow 180ms ease;
}
.kt-avatar[data-shape="square"] .kt-avatar-face { border-radius: var(--kt-radius-row); }
.kt-avatar-initials {
font-size: calc(var(--_s) * 0.38);
font-weight: 700;
line-height: 1;
letter-spacing: 0.02em;
user-select: none;
}
.kt-avatar-img {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
.kt-avatar-img[hidden] { display: none; }
.kt-avatar[data-loaded="true"] .kt-avatar-initials { visibility: hidden; }
.kt-avatar-status {
position: absolute;
right: 0;
bottom: 0;
width: max(9px, calc(var(--_s) * 0.26));
height: max(9px, calc(var(--_s) * 0.26));
border-radius: 50%;
background: #6b7280;
box-shadow: 0 0 0 2px var(--_ring);
box-sizing: border-box;
}
.kt-avatar[data-shape="square"] .kt-avatar-status { right: -3px; bottom: -3px; }
.kt-avatar-status[hidden] { display: none; }
.kt-avatar-status[data-status="online"] { background: #16a34a; }
.kt-avatar-status[data-status="away"] { background: #f59e0b; }
.kt-avatar-status[data-status="busy"] { background: #dc2626; }
.kt-avatar-status[data-status="offline"] {
background: var(--_ring);
border: 2px solid #6b7280;
}
[data-vfx="neon"] .kt-avatar-status[data-status="online"] { box-shadow: 0 0 0 2px var(--_ring), 0 0 8px 1px #16a34a; }
[data-vfx="sakuga"] .kt-avatar-status[data-status="online"],
[data-vfx="elastic"] .kt-avatar-status[data-status="online"] { animation: kt-avatar-pulse 2.4s ease-in-out infinite; }
[data-vfx="sakuga"] .kt-avatar:hover .kt-avatar-face { transform: scale(1.06); }
[data-vfx="elastic"] .kt-avatar:hover .kt-avatar-face { transform: scale(1.08, 0.94); }
[data-vfx="neon"] .kt-avatar:hover .kt-avatar-face { box-shadow: 0 0 0 2px var(--_ring), 0 0 14px 2px var(--_bg); }
@keyframes kt-avatar-pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.18); }
}
@media (prefers-reduced-motion: reduce) {
.kt-avatar-status,
.kt-avatar-face { animation: none !important; transition: none; transform: none !important; }
}
class KtKineticAvatar extends HTMLElement {
static get observedAttributes() {
return ["src", "name", "size", "status", "shape"];
}
constructor() {
super();
this._rendered = false;
}
connectedCallback() {
if (!this._rendered) {
this.render();
this._rendered = true;
}
this.syncAttributes();
}
attributeChangedCallback(name) {
if (!this._rendered) return;
this.syncAttributes(name === "src");
}
get name() { return (this.getAttribute("name") || "").trim(); }
get src() { return this.getAttribute("src") || ""; }
get size() {
const s = (this.getAttribute("size") || "md").toLowerCase();
return ["sm", "md", "lg", "xl"].includes(s) ? s : "md";
}
get status() {
const s = (this.getAttribute("status") || "").toLowerCase();
return ["online", "away", "busy", "offline"].includes(s) ? s : "";
}
get shape() { return this.getAttribute("shape") === "square" ? "square" : "circle"; }
static get palette() {
// deep enough for white text (4.5:1 or better), spread around the hue wheel
return ["#1d4ed8", "#6d28d9", "#a21caf", "#be123c", "#b45309", "#4d7c0f", "#047857", "#0e7490"];
}
get initials() {
const words = this.name.split(/\s+/).filter(Boolean);
if (!words.length) return "?";
const first = Array.from(words[0])[0];
const last = words.length > 1 ? Array.from(words[words.length - 1])[0] : Array.from(words[0])[1] || "";
return (first + last).toUpperCase();
}
colorFor(name) {
let h = 0;
for (let i = 0; i < name.length; i++) h = (h * 31 + name.charCodeAt(i)) >>> 0;
const p = KtKineticAvatar.palette;
return p[h % p.length];
}
render() {
this.innerHTML = "";
const root = document.createElement("span");
root.className = "kt-avatar";
root.setAttribute("role", "img");
root.innerHTML = `
<span class="kt-avatar-face">
<span class="kt-avatar-initials" aria-hidden="true"></span>
<img class="kt-avatar-img" alt="" aria-hidden="true" draggable="false" hidden />
</span>
<span class="kt-avatar-status" aria-hidden="true" hidden></span>
`;
this._root = root;
this._initialsEl = root.querySelector(".kt-avatar-initials");
this._img = root.querySelector(".kt-avatar-img");
this._statusEl = root.querySelector(".kt-avatar-status");
this._img.addEventListener("load", () => {
this._img.hidden = false;
root.setAttribute("data-loaded", "true");
});
this._img.addEventListener("error", () => {
this._img.hidden = true;
root.setAttribute("data-loaded", "false");
this.dispatchEvent(new CustomEvent("error", { detail: { src: this.src } }));
});
this.appendChild(root);
}
syncAttributes(srcChanged) {
if (!this._root) return;
const name = this.name;
const status = this.status;
this._root.setAttribute("data-size", this.size);
this._root.setAttribute("data-shape", this.shape);
this._root.style.setProperty("--_bg", this.colorFor(name || "?"));
this._initialsEl.textContent = this.initials;
const label = (name || "Avatar") + (status ? ", " + status : "");
this._root.setAttribute("aria-label", label);
this._statusEl.hidden = !status;
this._statusEl.setAttribute("data-status", status);
const src = this.src;
if (!src) {
this._img.hidden = true;
this._img.removeAttribute("src");
this._root.setAttribute("data-loaded", "false");
} else if (srcChanged || this._img.getAttribute("src") !== src) {
this._root.setAttribute("data-loaded", "false");
this._img.hidden = true;
this._img.src = src;
}
}
}
customElements.define("kt-kinetic-avatar", KtKineticAvatar);
function contrastInk(hex) {
const clean = hex.replace("#", "");
if (clean.length !== 6) return "#ffffff";
const r = parseInt(clean.slice(0, 2), 16);
const g = parseInt(clean.slice(2, 4), 16);
const b = parseInt(clean.slice(4, 6), 16);
const lum = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
return lum > 0.6 ? "#09090b" : "#ffffff";
}
function readAccent(el) {
const val = getComputedStyle(el).getPropertyValue("--kt-accent").trim();
return val || "#09090b";
}
class SakugaVFXEngine {
constructor(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext("2d");
this.items = [];
this.rafId = null;
this.lastTime = 0;
this.textEnabled = false;
this.textOverride = "";
this.vfxTextColor = "auto";
this.resize();
window.addEventListener("resize", () => this.resize());
}
attach(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext("2d");
this.items = [];
this.resize();
}
resize() {
const dpr = Math.min(window.devicePixelRatio || 1, 2);
this.canvas.width = Math.floor(window.innerWidth * dpr);
this.canvas.height = Math.floor(window.innerHeight * dpr);
this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
}
getMode() {
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return "enterprise";
return document.documentElement.getAttribute("data-vfx") || "enterprise";
}
wake() {
if (this.rafId !== null) return;
this.lastTime = performance.now();
const tick = (now) => {
const dt = Math.min((now - this.lastTime) / 1000, 0.05);
this.lastTime = now;
this.render(dt);
if (this.items.length > 0) {
this.rafId = requestAnimationFrame(tick);
} else {
this.rafId = null;
this.ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
}
};
this.rafId = requestAnimationFrame(tick);
}
emitBurst(x, y, color, { count = 14, speed = 240, spread = Math.PI * 2, baseAngle = 0, shards = true } = {}) {
if (this.getMode() === "enterprise") return;
for (let i = 0; i < count; i++) {
const angle = baseAngle + (Math.random() - 0.5) * spread;
const vel = speed * (0.45 + Math.random() * 0.75);
this.items.push({
kind: shards && i % 3 === 0 ? "shard" : "spark",
x, y,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel - (spread > 4 ? 35 : 0),
gravity: 400,
drag: 0.94,
size: 3 + Math.random() * 4,
rot: Math.random() * Math.PI * 2,
vrot: (Math.random() - 0.5) * 14,
life: 0,
maxLife: 0.32 + Math.random() * 0.22,
color
});
}
this.wake();
}
emitShockwave(x, y, color, maxRadius = 64) {
if (this.getMode() === "enterprise") return;
this.items.push({ kind: "ring", x, y, radius: 8, maxRadius, life: 0, maxLife: 0.32, color });
this.wake();
}
emitSlash(x, y, color, angle = -0.3) {
if (this.getMode() === "enterprise") return;
this.items.push({ kind: "slash", x, y, angle, length: 96, life: 0, maxLife: 0.2, color });
this.wake();
}
emitSmoke(x, y, color, dirX = 0) {
if (this.getMode() === "enterprise") return;
for (let i = 0; i < 4; i++) {
this.items.push({
kind: "smoke",
x: x + (Math.random() - 0.5) * 8,
y: y + (Math.random() - 0.5) * 8,
vx: dirX * (50 + Math.random() * 70) + (Math.random() - 0.5) * 35,
vy: -20 - Math.random() * 50,
size: 5 + Math.random() * 5,
life: 0,
maxLife: 0.34 + Math.random() * 0.16,
color
});
}
this.wake();
}
emitPixels(x, y, color, count = 14) {
if (this.getMode() !== "glitch") return;
for (let i = 0; i < count; i++) {
const angle = Math.floor(Math.random() * 8) * (Math.PI / 4);
const vel = 120 + Math.random() * 200;
this.items.push({
kind: "pixel",
x: x + (Math.random() - 0.5) * 18,
y: y + (Math.random() - 0.5) * 12,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel,
size: 4 + Math.floor(Math.random() * 5),
life: 0,
maxLife: 0.24 + Math.random() * 0.14,
color
});
}
this.wake();
}
emitScanline(x, y, color, width = 120) {
if (this.getMode() !== "glitch") return;
for (let i = -1; i <= 1; i += 2) {
this.items.push({
kind: "scanline",
x,
y: y + i * (5 + Math.random() * 6),
width,
life: 0,
maxLife: 0.18,
color
});
}
this.wake();
}
emitRays(x, y, color, count = 10, maxRadius = 72) {
if (this.getMode() !== "neon") return;
for (let i = 0; i < count; i++) {
const angle = (Math.PI * 2 * i) / count + (Math.random() - 0.5) * 0.18;
this.items.push({
kind: "ray",
x,
y,
angle,
maxRadius: maxRadius * (0.75 + Math.random() * 0.45),
life: 0,
maxLife: 0.34,
color
});
}
this.wake();
}
emitInkSplatter(x, y, color, count = 14) {
if (this.getMode() !== "ink") return;
for (let i = 0; i < count; i++) {
const angle = Math.random() * Math.PI * 2;
const vel = 110 + Math.random() * 230;
this.items.push({
kind: "inkblot",
x,
y,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel - 30,
gravity: 480,
drag: 0.91,
size: 2.5 + Math.random() * 5.5,
life: 0,
maxLife: 0.38 + Math.random() * 0.22,
color
});
}
// Brush arc sweep
this.items.push({
kind: "brusharc",
x,
y,
radius: 24 + Math.random() * 14,
startAngle: -Math.PI * 0.75,
endAngle: Math.PI * 0.35,
life: 0,
maxLife: 0.26,
color
});
this.wake();
}
emitMangaSFX(x, y, text, color) {
const mode = this.getMode();
const finalText = this.textOverride || text;
if (mode === "enterprise" || !this.textEnabled || !finalText || finalText === "none") return;
const fillColor = this.vfxTextColor !== "auto" ? this.vfxTextColor : color;
const outline = this.vfxTextColor !== "auto"
? contrastInk(this.vfxTextColor)
: (document.documentElement.getAttribute("data-bw") === "dark" ? "#09090b" : "#ffffff");
this.items.push({
kind: "sfx",
x: x + (Math.random() - 0.5) * 14,
y: y - 16,
vy: -48,
tilt: (Math.random() - 0.5) * 0.26,
text: finalText,
life: 0,
maxLife: 0.6,
color: fillColor,
outline
});
this.wake();
}
emitImpact(x, y, color, { sfx = "", scale = 1, dirX = 0, sfxY = y - 4 } = {}) {
const mode = this.getMode();
if (mode === "enterprise") return;
if (mode === "elastic") {
this.emitShockwave(x, y, color, Math.round(52 * scale));
this.emitSmoke(x, y, color, dirX);
} else if (mode === "glitch") {
this.emitPixels(x, y, color, Math.round(12 * scale));
this.emitScanline(x, y, color, Math.round(96 * scale));
} else if (mode === "neon") {
this.emitShockwave(x, y, color, Math.round(58 * scale));
this.emitRays(x, y, color, Math.round(9 * scale), Math.round(52 * scale));
} else if (mode === "ink") {
this.emitInkSplatter(x, y, color, Math.round(13 * scale));
} else {
this.emitShockwave(x, y, color, Math.round(50 * scale));
this.emitBurst(x, y, color, {
count: Math.round(12 * scale),
speed: Math.round(210 * scale),
spread: dirX ? 1.8 : Math.PI * 2,
baseAngle: dirX < 0 ? Math.PI : 0
});
this.emitSlash(x, y, color, -0.28);
}
this.emitMangaSFX(x, sfxY, sfx, color);
}
render(dt) {
const ctx = this.ctx;
ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
const next = [];
for (const p of this.items) {
p.life += dt;
if (p.life >= p.maxLife) continue;
const t = p.life / p.maxLife;
const easeOut = 1 - Math.pow(1 - t, 3);
const alpha = Math.max(0, 1 - Math.pow(t, 2));
ctx.save();
ctx.globalAlpha = alpha;
if (p.kind === "spark" || p.kind === "shard") {
p.vx *= Math.pow(p.drag, dt * 60);
p.vy = p.vy * Math.pow(p.drag, dt * 60) + p.gravity * dt;
p.x += p.vx * dt;
p.y += p.vy * dt;
p.rot += p.vrot * dt;
ctx.translate(p.x, p.y);
ctx.rotate(p.rot);
ctx.fillStyle = p.color;
if (p.kind === "shard") {
const s = p.size * (1 - t * 0.4);
ctx.beginPath();
ctx.moveTo(0, -s);
ctx.lineTo(s * 0.72, 0);
ctx.lineTo(0, s);
ctx.lineTo(-s * 0.72, 0);
ctx.closePath();
ctx.fill();
} else {
ctx.beginPath();
ctx.arc(0, 0, p.size * 0.5 * (1 - t * 0.5), 0, Math.PI * 2);
ctx.fill();
}
} else if (p.kind === "ring") {
const r = p.radius + (p.maxRadius - p.radius) * easeOut;
ctx.strokeStyle = p.color;
ctx.lineWidth = Math.max(1, 3 * (1 - t));
ctx.beginPath();
ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
ctx.stroke();
} else if (p.kind === "slash") {
ctx.translate(p.x, p.y);
ctx.rotate(p.angle);
const len = p.length * easeOut;
const th = 4.5 * (1 - t);
ctx.fillStyle = p.color;
ctx.beginPath();
ctx.moveTo(-len, 0);
ctx.quadraticCurveTo(0, -th, len, 0);
ctx.quadraticCurveTo(0, th, -len, 0);
ctx.fill();
} else if (p.kind === "smoke") {
p.x += p.vx * dt;
p.y += p.vy * dt;
const r = p.size * (0.8 + easeOut * 1.25);
ctx.fillStyle = p.color;
ctx.globalAlpha = 0.24 * (1 - t);
ctx.beginPath();
ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
ctx.fill();
} else if (p.kind === "pixel") {
p.x += p.vx * dt;
p.y += p.vy * dt;
ctx.fillStyle = p.color;
const s = p.size * (1 - t * 0.35);
ctx.fillRect(Math.round(p.x - s / 2), Math.round(p.y - s / 2), s, s);
} else if (p.kind === "scanline") {
const w = p.width * (0.4 + easeOut * 0.8);
ctx.fillStyle = p.color;
ctx.fillRect(p.x - w / 2, p.y, w, 2);
} else if (p.kind === "ray") {
const inner = 12 + easeOut * 16;
const outer = inner + p.maxRadius * (1 - t * 0.35);
ctx.strokeStyle = p.color;
ctx.shadowColor = p.color;
ctx.shadowBlur = 10;
ctx.lineWidth = Math.max(1, 2.8 * (1 - t));
ctx.beginPath();
ctx.moveTo(p.x + Math.cos(p.angle) * inner, p.y + Math.sin(p.angle) * inner);
ctx.lineTo(p.x + Math.cos(p.angle) * outer, p.y + Math.sin(p.angle) * outer);
ctx.stroke();
} else if (p.kind === "inkblot") {
p.vx *= Math.pow(p.drag, dt * 60);
p.vy = p.vy * Math.pow(p.drag, dt * 60) + p.gravity * dt;
p.x += p.vx * dt;
p.y += p.vy * dt;
ctx.fillStyle = p.color;
ctx.beginPath();
ctx.arc(p.x, p.y, p.size * (1 - t * 0.45), 0, Math.PI * 2);
ctx.fill();
} else if (p.kind === "brusharc") {
const sweep = p.startAngle + (p.endAngle - p.startAngle) * easeOut;
ctx.strokeStyle = p.color;
ctx.lineCap = "round";
ctx.lineWidth = Math.max(1.5, 6 * (1 - t));
ctx.beginPath();
ctx.arc(p.x, p.y, p.radius * (0.85 + easeOut * 0.4), p.startAngle, sweep);
ctx.stroke();
} else if (p.kind === "sfx") {
p.y += p.vy * dt * (1 - t * 0.6);
const s = t < 0.18 ? 0.55 + (t / 0.18) * 0.65 : 1.2 - (t - 0.18) * 0.25;
ctx.translate(p.x, p.y);
ctx.rotate(p.tilt);
ctx.scale(s, s);
ctx.font = '900 19px "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif';
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.lineJoin = "round";
ctx.lineWidth = 4.5;
ctx.strokeStyle = p.outline;
ctx.strokeText(p.text, 0, 0);
ctx.fillStyle = p.color;
ctx.fillText(p.text, 0, 0);
}
ctx.restore();
next.push(p);
}
this.items = next;
}
}
const SakugaFX = new SakugaVFXEngine(document.getElementById("sakuga-vfx-canvas"));
window.SakugaFX = SakugaFX;
window.readAccent = readAccent;
window.contrastInk = contrastInk;
Attributes
| Name | What it does | Default |
|---|---|---|
name | Full name. Gives the initials, the color and the accessible name. | — |
src | Image URL or data: URI. If it is missing or fails, the initials show. | — |
size | "sm" (28px), "md" (40px), "lg" (56px) or "xl" (80px). | md |
shape | "circle" or "square". | circle |
status | Presence dot: "online", "away", "busy" or "offline". | — |
Keyboard and screen readers
- role="img" with an aria-label made of the name and the status, for example "Mara Okafor, online".
- The image and initials inside are hidden from screen readers so the name is not read twice.
- The initials color comes from the name, so the same person always gets the same color; white text on every palette color meets 4.5:1.
- The avatar is not interactive. Wrap it in a button or link if it needs to be.
Styling variables
Every look is a CSS variable: --kt-accent, --kt-accent-ink, --kt-radius-btn, --kt-surface-radius, --kt-surface-bg, --kt-border-w, --kt-comp-shadow and --font-sans. The
copied file sets them all from your choices.
FAQ
Kinetic Avatar: questions answered
How do I use the Kinetic Avatar?
Press Copy on the card to get a complete HTML file, or copy the HTML, CSS and JavaScript tabs into your own page. In your markup the element is written as <kt-kinetic-avatar>.
Which attributes does <kt-kinetic-avatar> accept?
name, src, size, shape, status. Each one is described in the attributes table on this page.
Is the Kinetic Avatar accessible?
role="img" with an aria-label made of the name and the status, for example "Mara Okafor, online". The image and initials inside are hidden from screen readers so the name is not read twice. The initials color comes from the name, so the same person always gets the same color; white text on every palette color meets 4.5:1. The avatar is not interactive. Wrap it in a button or link if it needs to be.
Can I change the Kinetic Avatar colors, corners and font?
Yes. Use the options on this page: accent color, border radius, background, border, shadow and Google font. The copied code already contains your choices, and every one of them is a CSS variable you can edit later.