Skip to content

Avatar

Pro

A 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

By name or description, across the 46 props below

Avatar 33 props

  • nametype string

    The name the initials and the auto colour comes from.

  • icontype ReactNodedefault a person icon

    The fallback when there is no photo and no initials.

  • srctype string

    The photo's URL. The photo is drawn over the fallback, which shows until it loads or if it fails.

  • srcSettype string

    Responsive sources for the photo, as on <img>.

  • sizestype string

    Which srcSet source fits, as on <img>, e.g. "40px".

  • imagetype ReactElement<AvatarImageElementProps, string | JSXElementConstructor<any>>

    A custom image element (for example next/image) in place of src.

  • initialstype string

    Overrides the initials taken from name.

  • localetype stringdefault the page's locale, as the core's useLocale gives it

    Locale for the initials' casing (Turkish "i" → "İ").

  • sizetype number | AvatarSizedefault "md" (40px)

    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-size from 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.

  • shapetype AvatarShapedefault "circle"

    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 own MaterialShapePath (a closed path in the unit square). Its name goes to data-shape. Not mirrored in right-to-left, as in Compose.

  • colortype "auto" | "primary" | "secondary" | "tertiary" | "neutral"default "auto"

    auto hashes name into one of 12 colour slots, so a name keeps its colour. Each slot is a token pair, --wm-avatar-color-1 … --wm-avatar-color-12 with --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's data-color is the value given (auto too), and data-color-slot holds the slot number.

  • presencetype "online" | "away" | "offline"

    A presence dot. Its colours default to the theme's roles (online success, away warning, offline an outline ring) and can be overridden with the tokens --wm-avatar-online, --wm-avatar-away and --wm-avatar-offline, on :root, a section or one avatar. In forced colours they are CanvasText, GrayText and a ring.

  • presencePlacementtype "top-start" | "top-end" | "bottom-start" | "bottom-end"default "bottom-end"

    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 bottom for 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 from lg, 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 from lg) below the avatar for it.

  • ringtype booleandefault false

    Separates the avatar from overlapping neighbours with a 2px --wm-avatar-ring ring that follows its shape (set by AvatarGroup). Under a status ring the same colour fills the whole ring's reach instead.

  • reftype Ref<HTMLElement>

    The outermost element: the <span role="img">, or the link or button when interactive. Its other props (id, aria-*, data-*) go to it too.

  • reltype string

    A link avatar's rel, as on <a>. Only with href.

  • badgetype ReactNode

    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: badgeLabel gives its meaning, and for a word it should hold that word. false, null and an empty string draw no badge; 0 draws a "0". Its colours default to primary / on-primary (--wm-avatar-badge, --wm-avatar-on-badge).

  • badgeLabeltype string

    The badge's meaning, added to the accessible name ("Nora Lindqvist, verified"). Required with badge.

  • statusRingtype "active" | "inactive"

    A ring around the avatar, a small gap away from it, for a status an app shows on the avatar itself: active when there is something to see (something new from this account, a broadcast under way, the person speaking), inactive when there is nothing new. The active ring is primary, 2px wide (3px from lg); the inactive one is outline and 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 from lg) free around it. The tokens --wm-avatar-status-ring-active and --wm-avatar-status-ring-inactive take a colour or a gradient; --wm-avatar-status-ring-width, --wm-avatar-status-ring-inactive-width and --wm-avatar-status-ring-gap size it. Not the ring that separates overlapping avatars. In an AvatarGroup the 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 (see AvatarGroup's spacing). 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-offset of the ring's reach plus your own offset), or the ring covers it. On a decorative avatar, and on a static one in an AvatarGroup that 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.

  • statusRingLabeltype string

    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; with statusRing={undefined} (an account with nothing to show) it is left out of the name.

  • statusRingSegmentstype numberdefault 1

    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.

  • statusRingInactiveSegmentstype numberdefault 0

    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.

  • hreftype string

    Makes the avatar a link to this URL (the core's ButtonBase link), with a 48px target.

  • targettype HTMLAttributeAnchorTarget

    Where a link avatar opens, as on <a>. With "_blank" it opens a new tab: rel then always holds noopener noreferrer, and the name says so ("Nora Lindqvist, opens in a new tab", labels.newTab), as the library's Link does. Only with href.

  • downloadtype string | boolean

    Downloads what a link avatar points at instead of opening it, as on <a>; a string names the file. Only with href.

  • alttype string

    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.

  • decorativetype booleandefault false

    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 AvatarGroup static avatars are, except one inside your own link or button, which it names.

Events

  • onPresstype (() => void)

    Makes the avatar a button, with the core's state layer and ripple and a 48px target.

Text

  • labelstype Partial<AvatarLabels>

    Words added to the accessible name: the presence states, and a link that opens a new tab. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

AvatarGroup 13 props

  • childrentype ReactNodeRequired

    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 href or onPress to 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 its alt, and its item takes presses.

  • maxtype number

    Shows the first max avatars and a "+N" avatar for the rest.

  • sizetype number | AvatarSizedefault "md"

    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.

  • spacingtype "overlap" | "spaced"default "overlap"

    overlap stacks the avatars with a separating ring; spaced puts 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 from lg): className="gap-[12px]". In a group of links or buttons add the ! (gap-[12px]!) from md up, to pass the group's own spacing rule; at xs and sm that rule is wider already and keeps the rings apart, so leave it.

  • reftype Ref<HTMLDivElement>

    The group element. Its other props (id, style, aria-*, data-*) go to it too.

  • overflowHreftype string

    Makes the "+N" avatar a link to the full list, named by labels.overflow.

Events

  • onOverflowPresstype (() => void)

    Makes the "+N" avatar a button, for example to open the full list in a dialog; named by labels.overflow.

Text

  • labelstype Partial<AvatarGroupLabels>

    Words it announces, such as the "+N" avatar's name. A LabelsProvider sets them for the whole app.

  • aria-labeltype string

    Names the whole group, read once, for example "Alex, Sam and 3 others".

    One of aria-label or aria-labelledby is required.

  • aria-labelledbytype string

    The id of an element whose text names the group, instead of aria-label.

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.

  • 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

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-12 and their --wm-avatar-on-color-* text colours (any colour: a theme variable, hex, oklch()). data-color is the color prop as given (auto by default); with auto, data-color-slot holds the slot (1–12) the name hashed into.
  • Status colours default to M3 roles (online success, away warning, offline an outline ring, badge primary), 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.statusRing reaches every layer of the ring. In forced colours it is Highlight when active and GrayText when inactive.
  • Set the tokens on :root, a section or one avatar, in CSS or with Tailwind ([--wm-avatar-color-1:#16a34a]); the root carries data-tokens="wm-avatar". Tailwind classes on the parts win too: classNames={{ visual: 'bg-green-600 text-white' }}, and classNames.stateLayer styles 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 CanvasText edge; presence keeps its meaning: online CanvasText, away GrayText, 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").
Avatar tokens
VariableDefaultPaints
--wm-avatar-size40pxVaries 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-1var(--md-sys-color-primary-container)Colour slot 1 of `color="auto"`: the container.
--wm-avatar-on-color-1var(--md-sys-color-on-primary-container)Colour slot 1 of `color="auto"`: the initials or icon on it.
--wm-avatar-color-2var(--md-sys-color-secondary-container)Colour slot 2 of `color="auto"`: the container.
--wm-avatar-on-color-2var(--md-sys-color-on-secondary-container)Colour slot 2 of `color="auto"`: the initials or icon on it.
--wm-avatar-color-3var(--md-sys-color-tertiary-container)Colour slot 3 of `color="auto"`: the container.
--wm-avatar-on-color-3var(--md-sys-color-on-tertiary-container)Colour slot 3 of `color="auto"`: the initials or icon on it.
--wm-avatar-color-4var(--md-sys-color-surface-container-highest)Colour slot 4 of `color="auto"`: the container.
--wm-avatar-on-color-4var(--md-sys-color-on-surface-variant)Colour slot 4 of `color="auto"`: the initials or icon on it.
--wm-avatar-color-5var(--md-sys-color-primary-container)Colour slot 5 of `color="auto"`: the container.
--wm-avatar-on-color-5var(--md-sys-color-on-primary-container)Colour slot 5 of `color="auto"`: the initials or icon on it.
--wm-avatar-color-6var(--md-sys-color-secondary-container)Colour slot 6 of `color="auto"`: the container.
--wm-avatar-on-color-6var(--md-sys-color-on-secondary-container)Colour slot 6 of `color="auto"`: the initials or icon on it.
--wm-avatar-color-7var(--md-sys-color-tertiary-container)Colour slot 7 of `color="auto"`: the container.
--wm-avatar-on-color-7var(--md-sys-color-on-tertiary-container)Colour slot 7 of `color="auto"`: the initials or icon on it.
--wm-avatar-color-8var(--md-sys-color-surface-container-highest)Colour slot 8 of `color="auto"`: the container.
--wm-avatar-on-color-8var(--md-sys-color-on-surface-variant)Colour slot 8 of `color="auto"`: the initials or icon on it.
--wm-avatar-color-9var(--md-sys-color-primary-container)Colour slot 9 of `color="auto"`: the container.
--wm-avatar-on-color-9var(--md-sys-color-on-primary-container)Colour slot 9 of `color="auto"`: the initials or icon on it.
--wm-avatar-color-10var(--md-sys-color-secondary-container)Colour slot 10 of `color="auto"`: the container.
--wm-avatar-on-color-10var(--md-sys-color-on-secondary-container)Colour slot 10 of `color="auto"`: the initials or icon on it.
--wm-avatar-color-11var(--md-sys-color-tertiary-container)Colour slot 11 of `color="auto"`: the container.
--wm-avatar-on-color-11var(--md-sys-color-on-tertiary-container)Colour slot 11 of `color="auto"`: the initials or icon on it.
--wm-avatar-color-12var(--md-sys-color-surface-container-highest)Colour slot 12 of `color="auto"`: the container.
--wm-avatar-on-color-12var(--md-sys-color-on-surface-variant)Colour slot 12 of `color="auto"`: the initials or icon on it.
--wm-avatar-onlinevar(--md-sys-color-success)The presence dot when online.
--wm-avatar-awayvar(--md-sys-color-warning)The presence dot when away.
--wm-avatar-offlinevar(--md-sys-color-outline)The presence ring when offline (on a `surface` centre).
--wm-avatar-ringvar(--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-badgevar(--md-sys-color-primary)The badge’s container.
--wm-avatar-on-badgevar(--md-sys-color-on-primary)The badge’s content.
--wm-avatar-status-ring-activevar(--md-sys-color-primary)The status ring of `statusRing="active"`. A `background`, so it takes a colour or a gradient.
--wm-avatar-status-ring-inactivevar(--md-sys-color-outline)The status ring of `statusRing="inactive"`. A `background`, so it takes a colour or a gradient.
--wm-avatar-status-ring-width2pxVaries 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-width1pxThe 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-gap2pxThe space between the avatar and an active status ring.
--wm-avatar-status-ring-segment-gap7.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.