Avatar
ProA picture with an initials or icon fallback, badges, 35 Expressive shapes and groups. Not an M3 component (@windmorph/react-pro).
import { Avatar, AvatarGroup } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Props
Avatar 33 props
The name the initials and the auto colour comes from.
The fallback when there is no photo and no initials.
The photo's URL. The photo is drawn over the fallback, which shows until it loads or if it fails.
Responsive sources for the photo, as on
<img>.Which
srcSetsource fits, as on<img>, e.g."40px".A custom image element (for example
next/image) in place ofsrc.Overrides the initials taken from
name.Locale for the initials' casing (Turkish "i" → "İ").
24, 32, 40, 56, 72 or 96px (
xs…2xl), or any size in px (size={48}), in px so the avatar keeps its slot size at any text size. A number takes its corners, initials and rings from the nearest named size (a tie, the larger).--wm-avatar-sizefrom CSS sizes the box, its touch target and a group's spacing, keeping the rest of the named size's. Inside an AvatarGroup, the group's size wins.circle,rounded(a shape-scale corner for the size) or a shape outline, drawn as a CSS mask: an M3 Expressive shape from@windmorph/react/primitives(shape={cookie12SidedShape}) or an app's ownMaterialShapePath(a closed path in the unit square). Itsnamegoes todata-shape. Not mirrored in right-to-left, as in Compose.autohashesnameinto one of 12 colour slots, so a name keeps its colour. Each slot is a token pair,--wm-avatar-color-1…--wm-avatar-color-12with--wm-avatar-on-color-1…--wm-avatar-on-color-12(avatar-tokens.ts), which takes any colour; by default the slots cycle through the primary, secondary, tertiary and neutral containers. The root'sdata-coloris the value given (autotoo), anddata-color-slotholds the slot number.A presence dot. Its colours default to the theme's roles (online
success, awaywarning, offline anoutlinering) and can be overridden with the tokens--wm-avatar-online,--wm-avatar-awayand--wm-avatar-offline, on:root, a section or one avatar. In forced colours they areCanvasText,GrayTextand a ring.Where the presence dot sits. Beside a badge at the bottom (
badgePlacement="bottom"), a dot in a bottom corner moves to the top corner on its side, clear of the pill.badgePlacementtype"top-start" | "top-end" | "bottom-start" | "bottom-end" | "bottom"default"top-end"Where the badge sits: a corner, or
bottomfor a short word such as "LIVE", drawn as M3's large badge: a pill centred on the avatar's bottom edge, half below it, as tall as its line of text (16px, 20px fromlg, growing with the text size) and as wide as its content, up to 8px past the avatar on each side, where a longer word is cut short. Leave 8px (10px fromlg) below the avatar for it.Separates the avatar from overlapping neighbours with a 2px
--wm-avatar-ringring that follows its shape (set by AvatarGroup). Under a status ring the same colour fills the whole ring's reach instead.The outermost element: the
<span role="img">, or the link or button when interactive. Its other props (id,aria-*,data-*) go to it too.A link avatar's
rel, as on<a>. Only withhref.A badge, in a corner or at the bottom (
badgePlacement): an icon or short content, such as a check for "verified", a count or a word. Decorative:badgeLabelgives its meaning, and for a word it should hold that word.false,nulland an empty string draw no badge;0draws a "0". Its colours default toprimary/on-primary(--wm-avatar-badge,--wm-avatar-on-badge).The badge's meaning, added to the accessible name ("Nora Lindqvist, verified"). Required with
badge.A ring around the avatar, a small gap away from it, for a status an app shows on the avatar itself:
activewhen there is something to see (something new from this account, a broadcast under way, the person speaking),inactivewhen there is nothing new. The active ring isprimary, 2px wide (3px fromlg); the inactive one isoutlineand 1px, so the two differ in weight as well as colour. It is drawn outside the avatar's box, which keeps its size: leave the gap and the width (4px, 5px fromlg) free around it. The tokens--wm-avatar-status-ring-activeand--wm-avatar-status-ring-inactivetake a colour or a gradient;--wm-avatar-status-ring-width,--wm-avatar-status-ring-inactive-widthand--wm-avatar-status-ring-gapsize it. Not theringthat separates overlapping avatars. In anAvatarGroupthe avatar is drawn above its neighbours' photos, under their dots and badges, and takes no more room for the ring, so one that appears or goes moves nothing: in a spaced group, widen the gap for the rings (seeAvatarGroup'sspacing). A link or button avatar moves its focus indicator out past the ring; your own link or button around a static avatar must do the same (outline-offsetof the ring's reach plus your own offset), or the ring covers it. On adecorativeavatar, and on a static one in anAvatarGroupthat isn't inside your own link or button, nothing announces the ring: say what it means in the text beside the avatar, or in the group's label.What the ring means, added to the accessible name ("Nora Lindqvist, new story"), since a ring alone says nothing to a screen reader. Required with
statusRing; withstatusRing={undefined}(an account with nothing to show) it is left out of the name.Splits the ring into this many equal segments, one for each thing there is to see, with a small gap between them (
--wm-avatar-status-ring-segment-gap, an angle). 1, the default, is a whole ring. At most 20 are drawn: a larger count is drawn as 20, with the same share of them inactive and at least one of each kind the count had.How many of the segments are inactive: the ones already seen. They come first, from the top going clockwise, and the rest are active. With every segment inactive, or with
statusRing="inactive", the ring is drawn inactive, a whole ring too.Makes the avatar a link to this URL (the core's
ButtonBaselink), with a 48px target.Where a link avatar opens, as on
<a>. With"_blank"it opens a new tab:relthen always holdsnoopener noreferrer, and the name says so ("Nora Lindqvist, opens in a new tab",labels.newTab), as the library'sLinkdoes. Only withhref.Downloads what a link avatar points at instead of opening it, as on
<a>; a string names the file. Only withhref.The accessible name, usually the person's or page's name; presence, the badge's label and the status ring's are added to it. Required for a link or button avatar, and for a static one unless
decorative.Hides the avatar from assistive technology, when the name is written next to it. Its presence, badge and status ring are hidden with it, so that text must say what they mean. Only a static avatar can be decorative; in an
AvatarGroupstatic avatars are, except one inside your own link or button, which it names.
Events
Makes the avatar a button, with the core's state layer and ripple and a 48px target.
Text
Words added to the accessible name: the presence states, and a link that opens a new tab. A
LabelsProvidersets them for the whole app.Added to the name when
presence="online".Added to the name when
presence="away".Added to the name when
presence="offline".Added to the name of a link avatar with
target="_blank".
Classes for each part, merged over the library's.
The outermost element (the link or button when interactive); merged with
className.The coloured shape behind the photo and fallback, e.g.
bg-green-600 text-white.The photo.
The initials or icon shown without a photo.
The state layer of a link or button avatar, over the photo once it has loaded.
The presence dot.
The badge.
The status ring's layers: in segments the inactive ones and the active ones are a layer each, and both take this. For its paint use the tokens (
--wm-avatar-status-ring-activetakes a gradient): a class's paint would colour both layers alike.
Classes on the outermost element; merged with
classNames.root.Inline styles on the outermost element, e.g.
--wm-avatar-*token values.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
AvatarGroup 13 props
The avatars, one per child. A child can be an Avatar or any component that renders one: the group reaches it through context, however deeply it's wrapped. Give an Avatar
hreforonPressto make it a link or button; an app's own link or button around a static Avatar works too (a router's link, say): the avatar then names it with itsalt, and its item takes presses.Shows the first
maxavatars and a "+N" avatar for the rest.The size of every avatar in the group: a named size, or any size in px (
size={48}). The avatars overlap by a quarter of it, and links or buttons are spaced so their 48px targets never meet.overlapstacks the avatars with a separating ring;spacedputs a gap between them. When two or more avatars (the "+N" one included) are links or buttons, the group is spaced whatever this says, with a gap that keeps their 48px touch targets apart. An avatar with a status ring is drawn above its neighbours' photos and takes no more room, so a spaced group whose avatars have rings needs a wider gap, 12px or more (14px fromlg):className="gap-[12px]". In a group of links or buttons add the!(gap-[12px]!) frommdup, to pass the group's own spacing rule; atxsandsmthat rule is wider already and keeps the rings apart, so leave it.The group element. Its other props (
id,style,aria-*,data-*) go to it too.Makes the "+N" avatar a link to the full list, named by
labels.overflow.
Events
Makes the "+N" avatar a button, for example to open the full list in a dialog; named by
labels.overflow.
Text
Words it announces, such as the "+N" avatar's name. A
LabelsProvidersets them for the whole app.Names the whole group, read once, for example "Alex, Sam and 3 others".
One of
aria-labeloraria-labelledbyis required.The id of an element whose text names the group, instead of
aria-label.
Classes for each part, merged over the library's.
Classes on the group; merged with
classNames.root.Inline styles for the root element.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Spec status
Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.
| Item | Status | Details |
|---|---|---|
A photo (src) | Built | Variant · Photos |
| Initials and icon fallbacks | Built | Variant · Fallbacks |
Sizes: xs to 2xl (24 to 96px) | Built | Configuration · Fallbacks, Photos |
Any size in px (size={48}, --wm-avatar-size) | Built | Configuration · Any size |
| Circle, rounded and the 35 M3 Expressive shapes (shape constants) | Built | Configuration · Shapes |
Colours: auto per name, or a fixed role | Built | Configuration · Colors |
| Presence and badges | Built | Configuration · Badges |
A status ring and its segments (statusRing, statusRingSegments) | Built | Configuration · Status ring |
Stories: a gradient ring (--wm-avatar-status-ring-active) | Built | Use case · Stories |
| A gradient ring at every size | Built | Configuration · Ring sizes |
Live now: a ring and a pill at the bottom (badgePlacement="bottom") | Built | Use case · Live |
A link to a profile (href) | Built | Use case · Photos |
Groups with "+N" (AvatarGroup) | Built | Configuration · Group |
| Linked avatars in a group, in an app's own component, spaced for their touch targets | Built | Use case · Group links |
A photo (
Builtsrc)Variant · Photos
Initials and icon fallbacks
BuiltVariant · Fallbacks
Any size in px (
Builtsize={48},--wm-avatar-size)Configuration · Any size
Circle, rounded and the 35 M3 Expressive shapes (shape constants)
BuiltConfiguration · Shapes
Colours:
Builtautoper name, or a fixed roleConfiguration · Colors
Presence and badges
BuiltConfiguration · Badges
A status ring and its segments (
BuiltstatusRing,statusRingSegments)Configuration · Status ring
Stories: a gradient ring (
Built--wm-avatar-status-ring-active)Use case · Stories
A gradient ring at every size
BuiltConfiguration · Ring sizes
Live now: a ring and a pill at the bottom (
BuiltbadgePlacement="bottom")Use case · Live
A link to a profile (
Builthref)Use case · Photos
Groups with "+N" (
BuiltAvatarGroup)Configuration · Group
Linked avatars in a group, in an app's own component, spaced for their touch targets
BuiltUse case · Group links
M3 Expressive specs
- Sizes
xs, sm, md, lg, xl, 2xl- Shape
rounded-corner-full
Theming & tokens
color="auto"hashes the name into one of 12 colour slots, so a name keeps its colour. By default the slots cycle through the primary, secondary, tertiary and neutral containers, so they follow every theme, mode and contrast level. Give an app more colours by setting--wm-avatar-color-1…--wm-avatar-color-12and their--wm-avatar-on-color-*text colours (any colour: a theme variable, hex,oklch()).data-coloris thecolorprop as given (autoby default); withauto,data-color-slotholds the slot (1–12) the name hashed into.- Status colours default to M3 roles (online
success, awaywarning, offline anoutlinering, badgeprimary), all in the token set below. - The status ring is painted with
--wm-avatar-status-ring-active(primary) and--wm-avatar-status-ring-inactive(outline), which take a colour or a gradient; its width, its gap from the avatar and the gap between segments (an angle, with its unit) are tokens too. Paint it through the tokens:classNames.statusRingreaches every layer of the ring. In forced colours it isHighlightwhen active andGrayTextwhen inactive. - Set the tokens on
:root, a section or one avatar, in CSS or with Tailwind ([--wm-avatar-color-1:#16a34a]); the root carriesdata-tokens="wm-avatar". Tailwind classes on the parts win too:classNames={{ visual: 'bg-green-600 text-white' }}, andclassNames.stateLayerstyles the state layer of a link or button avatar. - In forced colours an Expressive shape becomes a circle, and the shape and the badge keep a
CanvasTextedge; presence keeps its meaning: onlineCanvasText, awayGrayText, offline a ring. - Rounded squares take a corner from the shape scale for their size; Expressive shapes are masks, so they scale with the avatar.
- Initials are whole graphemes in the locale's casing, so accented letters stay with their letters ("Élodie Dubois" → "ÉD").
| Variable | Default | Paints |
|---|---|---|
--wm-avatar-size | 40pxVaries with size. | The avatar's width and height, in px so it keeps its slot at any text size: 24, 32, 40, 56, 72 or 96px with `size`, or any size with `size={48}`, whose corners, initials and rings follow the nearest named size. Set from a theme or a class, it sizes the box, its touch target and a group's spacing; the corners, initials and rings stay the `size` prop's. |
--wm-avatar-color-1 | var(--md-sys-color-primary-container) | Colour slot 1 of `color="auto"`: the container. |
--wm-avatar-on-color-1 | var(--md-sys-color-on-primary-container) | Colour slot 1 of `color="auto"`: the initials or icon on it. |
--wm-avatar-color-2 | var(--md-sys-color-secondary-container) | Colour slot 2 of `color="auto"`: the container. |
--wm-avatar-on-color-2 | var(--md-sys-color-on-secondary-container) | Colour slot 2 of `color="auto"`: the initials or icon on it. |
--wm-avatar-color-3 | var(--md-sys-color-tertiary-container) | Colour slot 3 of `color="auto"`: the container. |
--wm-avatar-on-color-3 | var(--md-sys-color-on-tertiary-container) | Colour slot 3 of `color="auto"`: the initials or icon on it. |
--wm-avatar-color-4 | var(--md-sys-color-surface-container-highest) | Colour slot 4 of `color="auto"`: the container. |
--wm-avatar-on-color-4 | var(--md-sys-color-on-surface-variant) | Colour slot 4 of `color="auto"`: the initials or icon on it. |
--wm-avatar-color-5 | var(--md-sys-color-primary-container) | Colour slot 5 of `color="auto"`: the container. |
--wm-avatar-on-color-5 | var(--md-sys-color-on-primary-container) | Colour slot 5 of `color="auto"`: the initials or icon on it. |
--wm-avatar-color-6 | var(--md-sys-color-secondary-container) | Colour slot 6 of `color="auto"`: the container. |
--wm-avatar-on-color-6 | var(--md-sys-color-on-secondary-container) | Colour slot 6 of `color="auto"`: the initials or icon on it. |
--wm-avatar-color-7 | var(--md-sys-color-tertiary-container) | Colour slot 7 of `color="auto"`: the container. |
--wm-avatar-on-color-7 | var(--md-sys-color-on-tertiary-container) | Colour slot 7 of `color="auto"`: the initials or icon on it. |
--wm-avatar-color-8 | var(--md-sys-color-surface-container-highest) | Colour slot 8 of `color="auto"`: the container. |
--wm-avatar-on-color-8 | var(--md-sys-color-on-surface-variant) | Colour slot 8 of `color="auto"`: the initials or icon on it. |
--wm-avatar-color-9 | var(--md-sys-color-primary-container) | Colour slot 9 of `color="auto"`: the container. |
--wm-avatar-on-color-9 | var(--md-sys-color-on-primary-container) | Colour slot 9 of `color="auto"`: the initials or icon on it. |
--wm-avatar-color-10 | var(--md-sys-color-secondary-container) | Colour slot 10 of `color="auto"`: the container. |
--wm-avatar-on-color-10 | var(--md-sys-color-on-secondary-container) | Colour slot 10 of `color="auto"`: the initials or icon on it. |
--wm-avatar-color-11 | var(--md-sys-color-tertiary-container) | Colour slot 11 of `color="auto"`: the container. |
--wm-avatar-on-color-11 | var(--md-sys-color-on-tertiary-container) | Colour slot 11 of `color="auto"`: the initials or icon on it. |
--wm-avatar-color-12 | var(--md-sys-color-surface-container-highest) | Colour slot 12 of `color="auto"`: the container. |
--wm-avatar-on-color-12 | var(--md-sys-color-on-surface-variant) | Colour slot 12 of `color="auto"`: the initials or icon on it. |
--wm-avatar-online | var(--md-sys-color-success) | The presence dot when online. |
--wm-avatar-away | var(--md-sys-color-warning) | The presence dot when away. |
--wm-avatar-offline | var(--md-sys-color-outline) | The presence ring when offline (on a `surface` centre). |
--wm-avatar-ring | var(--md-sys-color-surface) | The 2px ring that separates the presence dot, the badge and overlapping avatars from what is behind them; under a status ring in an overlapping group it fills the whole ring’s reach. |
--wm-avatar-badge | var(--md-sys-color-primary) | The badge’s container. |
--wm-avatar-on-badge | var(--md-sys-color-on-primary) | The badge’s content. |
--wm-avatar-status-ring-active | var(--md-sys-color-primary) | The status ring of `statusRing="active"`. A `background`, so it takes a colour or a gradient. |
--wm-avatar-status-ring-inactive | var(--md-sys-color-outline) | The status ring of `statusRing="inactive"`. A `background`, so it takes a colour or a gradient. |
--wm-avatar-status-ring-width | 2pxVaries with size. | The width of an active status ring (2px; 3px from `lg`). With the gap, it is how far the ring reaches past the avatar, whichever its state. |
--wm-avatar-status-ring-inactive-width | 1px | The width of an inactive status ring, thinner than an active one so the two differ in more than colour. Never drawn wider than the active width. |
--wm-avatar-status-ring-gap | 2px | The space between the avatar and an active status ring. |
--wm-avatar-status-ring-segment-gap | 7.5degVaries with size. | The gap between the segments of a status ring in segments: an angle with its unit (`0deg` for none; a bare `0` is not an angle, and the ring loses its shape). Its default changes with the size (12° at `xs` to 3.5° at `2xl`), so the gap stays about 3px along the ring. Never drawn wider than half a segment. |