Avatar
Image or initials, with a status dot.
Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/, installsradix-ui@base-ui/reactand the colour tokens go into your CSS. This is the Radix build. Drop --radix for Base UI.This is the Base UI build, the default. Want Radix? Add --radix.$ pnpm dlx asta-ui@latest add avatar --radixOr install the package
Don’t want the file? Import from
asta-uiasta-ui/baseand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-ui radix-ui @base-ui/reactimport { Avatar } from "asta-ui";import { Avatar } from "asta-ui/base";Or copy it by hand
Install
radix-ui@base-ui/react, then copy this file. Keep the paths, or fix the@/imports. Then add the tokens fromglobals.css."use client"; import { Avatar as A } from "radix-ui"; import type { CSSProperties, ReactNode } from "react"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export type AvatarSize = "xs" | "sm" | "md" | "lg" | "xl"; export type AvatarStatus = "online" | "away" | "busy" | "offline"; const SIZE: Record<AvatarSize, { box: string; text: string; dot: string }> = { xs: { box: "h-6 w-6", text: "text-[10px]", dot: "h-1.5 w-1.5" }, sm: { box: "h-8 w-8", text: "text-[12px]", dot: "h-2 w-2" }, md: { box: "h-10 w-10", text: "text-[14px]", dot: "h-2.5 w-2.5" }, lg: { box: "h-12 w-12", text: "text-[16px]", dot: "h-3 w-3" }, xl: { box: "h-16 w-16", text: "text-[20px]", dot: "h-3.5 w-3.5" }, }; // Each status has its own shape too, so it reads without the colour: online solid, away a crescent, busy a bar, offline a ring. const PAPER = "var(--color-paper)"; const STATUS: Record<AvatarStatus, string> = { online: "var(--color-brand)", away: `radial-gradient(closest-side at 30% 30%, ${PAPER} 92%, var(--color-ink-2) 100%)`, busy: `linear-gradient(${PAPER}, ${PAPER}) center / 60% 20% no-repeat, var(--color-ink)`, offline: `radial-gradient(closest-side, ${PAPER} 48%, var(--color-mute) 56%)`, }; // Fallback fills: the name picks one, so the same person always gets the same colour. const FILLS = [ "bg-ink text-paper", "bg-brand text-on-brand", "bg-paper-2 text-ink shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_14%,transparent)]", "bg-[color-mix(in_srgb,var(--color-brand)_14%,var(--color-paper))] text-brand", "bg-[color-mix(in_srgb,var(--color-ink)_70%,var(--color-paper))] text-paper", ]; export const initials = (name: string) => name .split(/\s+/) .filter(Boolean) .slice(0, 2) .map((p) => p[0]!.toUpperCase()) .join(""); /** The fallback fill classes for a name. The same name always gets the same fill. */ export const avatarFill = (name: string) => FILLS[[...name].reduce((n, c) => n + c.charCodeAt(0), 0) % FILLS.length]; export interface AvatarProps { name: string; /** Image URL. Falls back to initials if missing or it fails to load. */ src?: string; size?: AvatarSize; status?: AvatarStatus; /** `circle` (default) or a soft `square` for teams and workspaces. */ shape?: "circle" | "square"; className?: string; } /** * A person or workspace, on Radix Avatar: the image only appears once it has loaded (no broken-image flash), * and initials on a fill picked from the name show while it loads or if it fails. */ export function Avatar({ name, src, size = "md", status, shape = "circle", className }: AvatarProps) { const s = SIZE[size]; const round = shape === "circle" ? "rounded-full" : "rounded-[30%]"; return ( <span className={cx("relative inline-flex shrink-0", s.box, className)} role="img" aria-label={status ? `${name} (${status})` : name}> <A.Root className={cx("flex h-full w-full select-none overflow-hidden bg-paper-2 font-medium tracking-[-0.02em]", round, s.text)}> {src && <A.Image src={src} alt="" className="h-full w-full object-cover animate-[kit-av-in_.3s_ease-out] motion-reduce:animate-none" />} <A.Fallback delayMs={src ? 250 : undefined} className={cx("flex h-full w-full items-center justify-center", avatarFill(name))}> {initials(name)} </A.Fallback> </A.Root> {/* React 19 dedupes this by href, so a group of avatars adds it once. */} <style href="kit-avatar" precedence="default">{`@keyframes kit-av-in { from { opacity: 0 } }`}</style> {status && ( <span aria-hidden className={cx("absolute bottom-0 right-0 rounded-full shadow-[0_0_0_2px_var(--color-paper)]", s.dot, shape === "square" && "-bottom-0.5 -right-0.5")} style={{ background: STATUS[status] }} /> )} </span> ); } // Fanning out moves each face right by 14px per position (from -10px overlap to a 4px gap) with transform, // so hovering never reflows the row. const FAN_ONLY = "group-hover/av:[transform:translateX(calc(var(--av-i)*14px))]"; const FAN = `-ml-2.5 ${FAN_ONLY}`; /** * Overlapping avatars that fan out on hover. Anything past `max` collapses into a "+N" chip. */ export function AvatarGroup({ people, max = 4, size = "md", children }: { people: { name: string; src?: string }[]; max?: number; size?: AvatarSize; children?: ReactNode }) { const shown = people.slice(0, max); const rest = people.length - shown.length; const s = SIZE[size]; return ( <div className="group/av flex items-center" aria-label={`${people.length} people`}> {shown.map((p, i) => ( <span key={p.name} title={p.name} className={cx( "relative rounded-full shadow-[0_0_0_2px_var(--color-paper)] transition-[transform] duration-500 ease-[cubic-bezier(.16,1,.3,1)] hover:z-10 hover:-translate-y-1", i > 0 && FAN, )} style={i > 0 ? ({ "--av-i": i } as CSSProperties) : undefined} > <Avatar name={p.name} src={p.src} size={size} /> </span> ))} {rest > 0 && ( <span className={cx( "relative inline-flex items-center justify-center rounded-full bg-paper-2 font-medium tabular-nums text-ink-2 shadow-[0_0_0_2px_var(--color-paper)] transition-[transform] duration-500 ease-[cubic-bezier(.16,1,.3,1)]", FAN, s.box, s.text, )} style={{ "--av-i": shown.length } as CSSProperties} > +{rest} </span> )} {children && ( <span className={cx("inline-flex items-center transition-[transform] duration-500 ease-[cubic-bezier(.16,1,.3,1)]", FAN_ONLY)} style={{ "--av-i": shown.length - 1 + (rest > 0 ? 1 : 0) } as CSSProperties}> {children} </span> )} </div> ); } export default Avatar;"use client"; import { Avatar as A } from "@base-ui/react/avatar"; import type { CSSProperties, ReactNode } from "react"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export type AvatarSize = "xs" | "sm" | "md" | "lg" | "xl"; export type AvatarStatus = "online" | "away" | "busy" | "offline"; const SIZE: Record<AvatarSize, { box: string; text: string; dot: string }> = { xs: { box: "h-6 w-6", text: "text-[10px]", dot: "h-1.5 w-1.5" }, sm: { box: "h-8 w-8", text: "text-[12px]", dot: "h-2 w-2" }, md: { box: "h-10 w-10", text: "text-[14px]", dot: "h-2.5 w-2.5" }, lg: { box: "h-12 w-12", text: "text-[16px]", dot: "h-3 w-3" }, xl: { box: "h-16 w-16", text: "text-[20px]", dot: "h-3.5 w-3.5" }, }; // Each status has its own shape too, so it reads without the colour: online solid, away a crescent, busy a bar, offline a ring. const PAPER = "var(--color-paper)"; const STATUS: Record<AvatarStatus, string> = { online: "var(--color-brand)", away: `radial-gradient(closest-side at 30% 30%, ${PAPER} 92%, var(--color-ink-2) 100%)`, busy: `linear-gradient(${PAPER}, ${PAPER}) center / 60% 20% no-repeat, var(--color-ink)`, offline: `radial-gradient(closest-side, ${PAPER} 48%, var(--color-mute) 56%)`, }; // Fallback fills: the name picks one, so the same person always gets the same colour. const FILLS = [ "bg-ink text-paper", "bg-brand text-on-brand", "bg-paper-2 text-ink shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_14%,transparent)]", "bg-[color-mix(in_srgb,var(--color-brand)_14%,var(--color-paper))] text-brand", "bg-[color-mix(in_srgb,var(--color-ink)_70%,var(--color-paper))] text-paper", ]; export const initials = (name: string) => name .split(/\s+/) .filter(Boolean) .slice(0, 2) .map((p) => p[0]!.toUpperCase()) .join(""); /** The fallback fill classes for a name. The same name always gets the same fill. */ export const avatarFill = (name: string) => FILLS[[...name].reduce((n, c) => n + c.charCodeAt(0), 0) % FILLS.length]; export interface AvatarProps { name: string; /** Image URL. Falls back to initials if missing or it fails to load. */ src?: string; size?: AvatarSize; status?: AvatarStatus; /** `circle` (default) or a soft `square` for teams and workspaces. */ shape?: "circle" | "square"; className?: string; } /** * A person or workspace, on Base UI Avatar: the image only appears once it has loaded (no broken-image flash), * and initials on a fill picked from the name show while it loads or if it fails. */ export function Avatar({ name, src, size = "md", status, shape = "circle", className }: AvatarProps) { const s = SIZE[size]; const round = shape === "circle" ? "rounded-full" : "rounded-[30%]"; return ( <span className={cx("relative inline-flex shrink-0", s.box, className)} role="img" aria-label={status ? `${name} (${status})` : name}> <A.Root className={cx("flex h-full w-full select-none overflow-hidden bg-paper-2 font-medium tracking-[-0.02em]", round, s.text)}> {src && <A.Image src={src} alt="" className="h-full w-full object-cover animate-[kit-av-in_.3s_ease-out] motion-reduce:animate-none" />} <A.Fallback delay={src ? 250 : undefined} className={cx("flex h-full w-full items-center justify-center", avatarFill(name))}> {initials(name)} </A.Fallback> </A.Root> {/* React 19 dedupes this by href, so a group of avatars adds it once. */} <style href="kit-avatar" precedence="default">{`@keyframes kit-av-in { from { opacity: 0 } }`}</style> {status && ( <span aria-hidden className={cx("absolute bottom-0 right-0 rounded-full shadow-[0_0_0_2px_var(--color-paper)]", s.dot, shape === "square" && "-bottom-0.5 -right-0.5")} style={{ background: STATUS[status] }} /> )} </span> ); } // Fanning out moves each face right by 14px per position (from -10px overlap to a 4px gap) with transform, // so hovering never reflows the row. const FAN_ONLY = "group-hover/av:[transform:translateX(calc(var(--av-i)*14px))]"; const FAN = `-ml-2.5 ${FAN_ONLY}`; /** * Overlapping avatars that fan out on hover. Anything past `max` collapses into a "+N" chip. */ export function AvatarGroup({ people, max = 4, size = "md", children }: { people: { name: string; src?: string }[]; max?: number; size?: AvatarSize; children?: ReactNode }) { const shown = people.slice(0, max); const rest = people.length - shown.length; const s = SIZE[size]; return ( <div className="group/av flex items-center" aria-label={`${people.length} people`}> {shown.map((p, i) => ( <span key={p.name} title={p.name} className={cx( "relative rounded-full shadow-[0_0_0_2px_var(--color-paper)] transition-[transform] duration-500 ease-[cubic-bezier(.16,1,.3,1)] hover:z-10 hover:-translate-y-1", i > 0 && FAN, )} style={i > 0 ? ({ "--av-i": i } as CSSProperties) : undefined} > <Avatar name={p.name} src={p.src} size={size} /> </span> ))} {rest > 0 && ( <span className={cx( "relative inline-flex items-center justify-center rounded-full bg-paper-2 font-medium tabular-nums text-ink-2 shadow-[0_0_0_2px_var(--color-paper)] transition-[transform] duration-500 ease-[cubic-bezier(.16,1,.3,1)]", FAN, s.box, s.text, )} style={{ "--av-i": shown.length } as CSSProperties} > +{rest} </span> )} {children && ( <span className={cx("inline-flex items-center transition-[transform] duration-500 ease-[cubic-bezier(.16,1,.3,1)]", FAN_ONLY)} style={{ "--av-i": shown.length - 1 + (rest > 0 ? 1 : 0) } as CSSProperties}> {children} </span> )} </div> ); } export default Avatar;Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Avatar component to my project. Image or initials, with a status dot. It includes: Avatar, AvatarGroup, status, sizes. Install it (Radix build): ```sh pnpm dlx asta-ui@latest add avatar --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/avatar.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Avatar, AvatarGroup } from "@/components/astabyte/avatar"; ``` Usage example and props: https://ui.astabyte.com/avatar Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Radix primitives from the radix-ui package). - Stay on Radix: install other Astabyte UI components with `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Add the Astabyte UI Avatar component to my project. Image or initials, with a status dot. It includes: Avatar, AvatarGroup, status, sizes. Install it (Base UI build): ```sh pnpm dlx asta-ui@latest add avatar ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/base/avatar.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Avatar, AvatarGroup } from "@/components/astabyte/avatar"; ``` Usage example and props: https://ui.astabyte.com/avatar Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Base UI primitives from the @base-ui/react package). - Stay on Base UI: install other Astabyte UI components without `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Or use plain HTML + CSS
Not on React? Use it from Django, Rails, Laravel, Go
html/template, htmx or a static page. Loadasta.cssandasta.jsonce (thehead.htmltab), then paste the markup. Theui.astabyte.com/cdnlink is temporary: pin a version from jsDelivr for production. More in HTML + CSS.<div style="display:flex;flex-wrap:wrap;align-items:center;gap:12px"> <span class="asta-avatar asta-avatar-xs" role="img" aria-label="Ada Lovelace"><span class="asta-avatar-face">AL</span></span> <span class="asta-avatar asta-avatar-sm" role="img" aria-label="Ada Lovelace (online)"><span class="asta-avatar-face">AL</span><span class="asta-avatar-status" data-status="online" aria-hidden="true"></span></span><span class="asta-avatar" role="img" aria-label="Grace Hopper (busy)"><span class="asta-avatar-face asta-avatar-brand">GH</span><span class="asta-avatar-status" data-status="busy" aria-hidden="true"></span></span> <span class="asta-avatar asta-avatar-lg asta-avatar-square" role="img" aria-label="Alan Turing (away)"><span class="asta-avatar-face asta-avatar-soft">AT</span><span class="asta-avatar-status" data-status="away" aria-hidden="true"></span></span> <span class="asta-avatar asta-avatar-lg" role="img" aria-label="Kenji Sato (offline)"><span class="asta-avatar-face asta-avatar-gray">KS</span><span class="asta-avatar-status" data-status="offline" aria-hidden="true"></span></span> <span class="asta-avatar asta-avatar-xl" role="img" aria-label="Linus T"><span class="asta-avatar-face asta-avatar-tint">LT</span></span> </div>
Usage
The demo above, as code.
"use client";
import { Avatar, AvatarGroup } from "@/components/astabyte/avatar";
// A tiny inline image, so the demo needs no network.
const PHOTO =
"data:image/svg+xml," +
encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" fill="#dfe5fb"/><circle cx="32" cy="26" r="11" fill="#2f54eb"/><path d="M12 64c2-14 10-20 20-20s18 6 20 20z" fill="#2f54eb"/></svg>`,
);
const TEAM = [
{ name: "Maya Putri" },
{ name: "Rizky Ananda", src: PHOTO },
{ name: "Lena Ortiz" },
{ name: "Kenji Sato" },
{ name: "Sara Bloom" },
{ name: "Omar Haddad" },
{ name: "Ines Duarte" },
];
const Row = ({ label, children }: { label: string; children: React.ReactNode }) => (
<div className="flex flex-col gap-3 sm:flex-row sm:items-center">
<span className="w-20 shrink-0 font-mono text-[11px] uppercase tracking-wider text-mute">{label}</span>
<div className="flex flex-wrap items-center gap-3">{children}</div>
</div>
);
export default function AvatarDemo() {
return (
<div className="flex min-h-[420px] w-full items-center justify-center p-6 sm:p-10">
<div className="flex flex-col gap-7">
<Row label="Size">
<Avatar name="Maya Putri" size="xs" />
<Avatar name="Maya Putri" size="sm" />
<Avatar name="Maya Putri" size="md" />
<Avatar name="Maya Putri" size="lg" />
<Avatar name="Maya Putri" size="xl" />
</Row>
<Row label="Fallback">
<Avatar name="Rizky Ananda" src={PHOTO} size="lg" />
<Avatar name="Lena Ortiz" size="lg" />
<Avatar name="Kenji Sato" size="lg" />
<Avatar name="Broken Image" src="/missing.png" size="lg" />
<Avatar name="Astabyte" shape="square" size="lg" />
</Row>
<Row label="Status">
<Avatar name="Sara Bloom" status="online" size="lg" />
<Avatar name="Omar Haddad" status="away" size="lg" />
<Avatar name="Ines Duarte" status="busy" size="lg" />
<Avatar name="Kenji Sato" status="offline" size="lg" />
</Row>
<Row label="Group">
<AvatarGroup people={TEAM} max={4}>
<span className="ml-3 text-[13px] text-mute">Hover to fan out</span>
</AvatarGroup>
</Row>
</div>
</div>
);
}