Skip to content

Avatar

Avatar shows a picture of a person or an agent, or their initials when there is no picture. AvatarGroup stacks several of them and folds the rest into a “+N” avatar.

Demos

Basic

size is small, medium or large (the same heights as buttons, so they line up in a row), or a number of pixels.

Shape and border

Avatars follow the theme’s corners: square in Brutal, softly rounded in Elegant. round makes a circle; bordered adds an ink border in Brutal and a quiet one in Elegant.

Text

Text starts at 40% of the avatar’s side and shrinks to fit when it is longer, so a full name still fits. Type to try it.

Color

color sets the background; set style.color for the text on it. The color roles work well for telling agents from people, and an icon works as well as initials.

Fallback

When src fails, the avatar tries fallbackSrc, then shows renderFallback or its children. The children also show while the image loads.

With a badge

Wrap the avatar in a Badge for an unread count or a status dot.

Group

AvatarGroup overlaps its avatars and borders them so they stay apart. With max, the ones that don’t fit become a “+N” avatar. size and round on the group apply to every avatar inside. Avatars can also be passed as children, and Avatar and PixelAvatar mix freely. expandOnHover spreads the stack out under the pointer; vertical stacks it top to bottom.

Name tooltips and a rest menu

The group itself opens nothing: renderAvatar wraps each avatar in a Tooltip with the name, and renderRest replaces the “+N” with a Dropdown that lists the hidden people on click.

Lazy loading

lazy alone uses the browser’s native lazy loading. With intersectionObserverOptions the image loads once it scrolls into the given root, and renderPlaceholder shows until then.

Avatar props

NameTypeDefaultDescriptionVersion
srcstringundefinedThe image URL.Unreleased
altstringundefinedThe image’s text alternative. Without it the image is decorative.Unreleased
childrenReactNodeundefinedText or an icon. Shown without src, while the image loads and when every image failed. Text shrinks to fit.Unreleased
sizesmall | medium | large | numbermediumNamed size or side length in px. Inside a group, the group’s size is the default.Unreleased
roundbooleanfalseA circle instead of the theme’s shape.Unreleased
borderedbooleanfalseAdds a border. Always on inside a group.Unreleased
colorstringundefinedBackground color.Unreleased
objectFitfill | contain | cover | none | scale-downcoverHow the image fills the avatar.Unreleased
fallbackSrcstringundefinedTried when src fails.Unreleased
renderFallback() => ReactNodeundefinedShown when every image failed. Defaults to children.Unreleased
renderPlaceholder() => ReactNodeundefinedShown while the image loads. Defaults to children.Unreleased
lazybooleanfalseLoads the image only near the viewport.Unreleased
intersectionObserverOptions{ root?, rootMargin?, threshold? }undefinedWith lazy, load once the avatar enters this root. root can be an element or a selector.Unreleased
imgPropsImgHTMLAttributesundefinedProps for the <img> element.Unreleased
onLoad(event) => voidundefinedCalled when the image has loaded.Unreleased
onError(event) => voidundefinedCalled when src or fallbackSrc fails to load.Unreleased

Avatar also accepts native span attributes and a ref. An avatar that shows only an icon should get role="img" and an aria-label.

AvatarGroup props

NameTypeDefaultDescriptionVersion
options{ src: string; alt?: string }[][]The avatars to show. The option type is generic.Unreleased
maxnumberundefinedShows at most this many avatars; when there are more, the last one becomes “+N”.Unreleased
maxStyleCSSPropertiesundefinedStyle for the “+N” avatar.Unreleased
sizesmall | medium | large | numberundefinedDefault size for the avatars inside.Unreleased
roundbooleanundefinedDefault round for the avatars inside.Unreleased
verticalbooleanfalseStacks the avatars top to bottom.Unreleased
expandOnHoverbooleanfalseSpreads the stack out while the pointer is over it.Unreleased
renderAvatar({ option }) => ReactNodeundefinedRenders one option.Unreleased
renderRest({ options, rest }) => ReactNodeundefinedRenders the “+N” avatar.Unreleased
childrenReactNodeundefinedAvatars placed before the ones from options.Unreleased

AvatarGroup renders a div with role="group"; give it an aria-label that says who is in it. The “+N” avatar reads as “N more”.