Avatar
Avatar example: a round user picture with image, fallback initials and a corner status badge, in small, default and large sizes. AvatarGroup overlaps faces with a ring and adds a remaining count.
"use client"
import * as React from "react"
import { Avatar as AvatarPrimitive } from "@base-ui/react/avatar"
import { cn } from "cn"
function Avatar({
className,
size = "default",
...props
}: AvatarPrimitive.Root.Props & {
size?: "default" | "sm" | "lg"
}) {
return (
<AvatarPrimitive.Root
data-slot="avatar"
data-size={size}
className={cn(
"group/avatar relative flex size-8 shrink-0 rounded-full select-none after:absolute after:inset-0 after:rounded-full after:border after:border-border after:mix-blend-darken data-[size=lg]:size-10 data-[size=sm]:size-6 dark:after:mix-blend-lighten",
className
)}
{...props}
/>
)
}
function AvatarImage({ className, ...props }: AvatarPrimitive.Image.Props) {
return (
<AvatarPrimitive.Image
data-slot="avatar-image"
className={cn(
"aspect-square size-full rounded-full object-cover",
className
)}
{...props}
/>
)
}
function AvatarFallback({
className,
...props
}: AvatarPrimitive.Fallback.Props) {
return (
<AvatarPrimitive.Fallback
data-slot="avatar-fallback"
className={cn(
"flex size-full items-center justify-center rounded-full bg-muted text-sm text-muted-foreground group-data-[size=sm]/avatar:text-xs",
className
)}
{...props}
/>
)
}
function AvatarBadge({ className, ...props }: React.ComponentProps<"span">) {
return (
<span
data-slot="avatar-badge"
className={cn(
"absolute right-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground bg-blend-color ring-2 ring-background select-none",
"group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden",
"group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2",
"group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2",
className
)}
{...props}
/>
)
}
function AvatarGroup({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="avatar-group"
className={cn(
"group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background",
className
)}
{...props}
/>
)
}
function AvatarGroupCount({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="avatar-group-count"
className={cn(
"relative flex size-8 shrink-0 items-center justify-center rounded-full bg-muted text-sm text-muted-foreground ring-2 ring-background group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3",
className
)}
{...props}
/>
)
}
export {
Avatar,
AvatarImage,
AvatarFallback,
AvatarGroup,
AvatarGroupCount,
AvatarBadge,
}
import { PaintedOrb } from "@/components/orbs/painted-orb"
import {
Avatar,
AvatarGroup,
AvatarGroupCount,
} from "@/components/ui/avatar"
// The copy: change text here, not in the markup.
const COPY = {
overflow: "+9",
} as const
const PEOPLE = [
{
name: "Ines",
gradient:
"linear-gradient(to bottom, #3a1f10 0%, #c2733a 60%, #f0b878 100%)",
limb: "#f0b878",
},
{
name: "Tomas",
gradient:
"linear-gradient(to bottom, #1d1a3a 0%, #5b4f9a 60%, #c9a8d8 100%)",
limb: "#c9a8d8",
},
{
name: "Priya",
gradient:
"linear-gradient(to bottom, #2a2f14 0%, #6b7a2f 60%, #c3c77a 100%)",
limb: "#c3c77a",
},
] as const
/** A stack of team avatars drawn as painted orbs, with an overflow count. */
export default function AvatarDemo() {
return (
<AvatarGroup>
{PEOPLE.map((person) => (
<Avatar key={person.name}>
<PaintedOrb
size={32}
gradient={person.gradient}
limbColor={person.limb}
glowIntensity={0}
className="shrink-0 self-start"
/>
<span className="sr-only">{person.name}</span>
</Avatar>
))}
<AvatarGroupCount>{COPY.overflow}</AvatarGroupCount>
</AvatarGroup>
)
}
Installation
pnpm dlx shadcn@latest add @01orbital/avatarnpx shadcn@latest add @01orbital/avataryarn dlx shadcn@latest add @01orbital/avatarbunx --bun shadcn@latest add @01orbital/avatarExamples
Moss Orbavatar-moss-orb
Avatar example: an avatar painted as the moss Cloudy Nimbus orb beside a name, decorative and hidden from assistive tech, with its ring off. Shows an orb as a generated profile picture.
The source comes with full access.
One payment of $149 opens the source right here and lets the CLI install every paid component, with lifetime updates.
pnpm dlx shadcn@latest add @01orbital/avatar-moss-orbnpx shadcn@latest add @01orbital/avatar-moss-orbyarn dlx shadcn@latest add @01orbital/avatar-moss-orbbunx --bun shadcn@latest add @01orbital/avatar-moss-orbAvatar components
The library's own avatar components, each installed on its own.
Planet Avatarplanet-avatar
Generated default avatar drawn as a planet: the name picks a colorway, so the same person always gets the same planet with nothing stored. Circle or squircle shape, handy as a user avatar or app icon fallback. Open its docs page
The source comes with full access.
One payment of $149 opens the source right here and lets the CLI install every paid component, with lifetime updates.
pnpm dlx shadcn@latest add @01orbital/planet-avatarnpx shadcn@latest add @01orbital/planet-avataryarn dlx shadcn@latest add @01orbital/planet-avatarbunx --bun shadcn@latest add @01orbital/planet-avatarDependencies
npm: @base-ui/react, cn. The CLI installs them for you.
Used in blocks
13 blocks are built with Avatar; the first 12:
About Community Avatar Wall
Accounts
Booking Capacity Table
Digital Download Product Page
Frosted Glass Guide Cards
Glow Rig Testimonial
Joined Rewards Tier Pricing
Profile Header With Tabs
Profile Settings with Tabs
Project Members Bar
Quote with brand row
Share
Last updated on