How to use
Avatar renders a user's profile image with a graceful fallback to initials (derived from name) or an icon when there's no src, or while the image is still loading. A companion AvatarGroup component stacks several Avatars with automatic overflow counting, for things like a list of collaborators on a document.
import { Avatar } from "oks-ui";Pass src for the image and name so there's something sensible to fall back to — Avatar derives initials from name automatically if the image fails to load or hasn't loaded yet. If you don't have a name either, pass icon for a generic fallback instead of leaving it blank.
<Avatar src={user.avatarUrl} name={user.fullName} />
<Avatar name="Ada Lovelace" /> {/* no src -- renders "AL" */}
<Avatar icon={<UserIcon />} /> {/* no src, no name -- renders the icon */}status renders a small colored dot in the corner for a presence indicator (online, offline, dnd) — built on the same positioning machinery Badge uses for its own dot mode, so it stays correctly anchored across every avatar size.
<Avatar src={user.avatarUrl} name={user.fullName} status="online" />For anything beyond initials or a single icon — a placeholder illustration, a different fallback per user type — pass fallback with any ReactNode; it takes priority over both icon and the derived initials. showFallback forces the fallback to render even while a valid image is still loading, useful if you'd rather show a stable placeholder than a flash of empty space.
By default the image renders as a plain <img>. Pass ImgComponent to render it through something else instead — next/image, for instance — with imgProps carrying whatever extra props that component needs (width/height, loader, etc.).
<Avatar
src={user.avatarUrl}
name={user.fullName}
ImgComponent={Image}
imgProps={{ width: 40, height: 40 }}
/>AvatarGroup stacks its children with a configurable overlap and shows a "+N" overflow count once there are more avatars than max — pass total instead of relying on children.length if the real total (e.g. from a paginated API) is larger than what's actually rendered.
import { Avatar, AvatarGroup } from "oks-ui";
<AvatarGroup max={4} total={12}>
{collaborators.map((c) => (
<Avatar key={c.id} src={c.avatarUrl} name={c.name} />
))}
</AvatarGroup>All available props for Avatar. See the full component page for an interactive playground.
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | — | Used to derive fallback initials. |
src | string | — | Image source URL. |
icon | ReactNode | — | Custom fallback icon, used when name/initials aren't available. |
fallback | ReactNode | — | Fully custom fallback content, overrides icon/initials. |
showFallback | boolean | false | Forces the fallback (initials/icon) even while an image is loading. |
name
string
Default: —
Used to derive fallback initials.
src
string
Default: —
Image source URL.
icon
ReactNode
Default: —
Custom fallback icon, used when name/initials aren't available.
fallback
ReactNode
Default: —
Fully custom fallback content, overrides icon/initials.
showFallback
boolean
Default: false
Forces the fallback (initials/icon) even while an image is loading.
| Prop | Type | Default | Description |
|---|---|---|---|
size | "xs" | "xs-sm" | "sm" | "md" | "lg" | "xl" | number | md | Token size, or a number for an exact px size (font-size scales ~0.4x; the status Badge maps to the nearest token bucket). AvatarGroup forces its size onto children. |
color | "default" | "primary" | "secondary" | "info" | "success" | "warning" | "danger" | default | Semantic color for the fallback background. |
radius | "none" | "xs" | "xs-sm" | "sm" | "md" | "lg" | "full" | full | Border radius. |
colorDepth | 50 | 100 | ... | 950 | 500 | Shade depth for the selected color. |
isBordered | boolean | false | Adds a ring border around the avatar. |
size
"xs" | "xs-sm" | "sm" | "md" | "lg" | "xl" | number
Default: md
Token size, or a number for an exact px size (font-size scales ~0.4x; the status Badge maps to the nearest token bucket). AvatarGroup forces its size onto children.
color
"default" | "primary" | "secondary" | "info" | "success" | "warning" | "danger"
Default: default
Semantic color for the fallback background.
radius
"none" | "xs" | "xs-sm" | "sm" | "md" | "lg" | "full"
Default: full
Border radius.
colorDepth
50 | 100 | ... | 950
Default: 500
Shade depth for the selected color.
isBordered
boolean
Default: false
Adds a ring border around the avatar.
| Prop | Type | Default | Description |
|---|---|---|---|
isDisabled | boolean | false | Dims the avatar and disables interaction. |
isFocusable | boolean | false | Makes the avatar keyboard-focusable. |
tooltip | ReactNode | boolean | (Omit<TooltipProps, "children"|"content"> & { content?: ReactNode }) | false | Wraps the avatar in a Tooltip. A plain value is shorthand content; bare true derives content from name; an object accepts any Tooltip prop plus an optional content override. |
status | "online" | "offline" | "dnd" | — | Status dot indicator. |
ImgComponent | ElementType | "img" | Renders the image through a different component (e.g. next/image). |
imgProps | ComponentPropsWithoutRef<ImgComponent> | — | Extra props forwarded to the image element/component. |
isDisabled
boolean
Default: false
Dims the avatar and disables interaction.
isFocusable
boolean
Default: false
Makes the avatar keyboard-focusable.
tooltip
ReactNode | boolean | (Omit<TooltipProps, "children"|"content"> & { content?: ReactNode })
Default: false
Wraps the avatar in a Tooltip. A plain value is shorthand content; bare true derives content from name; an object accepts any Tooltip prop plus an optional content override.
status
"online" | "offline" | "dnd"
Default: —
Status dot indicator.
ImgComponent
ElementType
Default: "img"
Renders the image through a different component (e.g. next/image).
imgProps
ComponentPropsWithoutRef<ImgComponent>
Default: —
Extra props forwarded to the image element/component.
| Prop | Type | Default | Description |
|---|---|---|---|
classNames | Partial<Record<AvatarSlot, string>> | — | Per-slot class overrides (base/img/fallback/name/icon/status). |
className | string | — | Class applied to the root element. |
classNames
Partial<Record<AvatarSlot, string>>
Default: —
Per-slot class overrides (base/img/fallback/name/icon/status).
className
string
Default: —
Class applied to the root element.