Skip to content

Basic Components

[02] Basic Components

Avatar

Avatar is a picture of a person or a team: an image, the initials of the name when there is none, or a person icon. AvatarGroup overlaps several in one row.

SourceEdit this page

Avatar is a small picture of a person, a team or a workspace: in a comment thread, a member list, a header or next to an assignee. It renders a <span> of a fixed size that shows the image from src, the initials of name when there is no image or it fails to load, or a person icon when there is neither. AvatarGroup shows several avatars as one overlapping row. For a photo that is part of the content, use Img. Avatar needs @vaneui/ui 1.8.0 or later.

const photo = "/puppy.webp";

Basic usage

Pass the image in src and the person's name in name. The name becomes the image's text alternative, so a screen reader reads "Biscuit" for the avatar below.

Biscuit

Biscuit commented on your pull request.

<Row>
<Avatar src={photo} name="Biscuit"/>
<Text>Biscuit commented on your pull request.</Text>
</Row>

Pass alt when the text alternative should differ from the name. With neither name nor alt, the image is decorative and gets alt="".

Initials and the person icon

Without an image, Avatar shows the first letters of the first and last word of name, in upper case. An image that fails to load falls back to the same initials, and a new src is tried again. With no image and no name, Avatar shows a person icon that is hidden from assistive technology.

ALGrace Brewster HopperÉD
<Row>
<Avatar name="Ada Lovelace"/>
<Avatar src="/missing-photo.png" name="Grace Brewster Hopper"/>
<Avatar name="élodie durand"/>
<Avatar/>
</Row>

Initials get role="img" and the name as their aria-label, so the letters are read as the person's name rather than spelled out.

Sizes

Size sets the box, the corner radius and the initials together: 24, 32, 40, 48 and 64px from xs to xl, with md (40px) as the default.

ALALALALAL
<Row>
<Avatar xs name="Ada Lovelace"/>
<Avatar sm name="Ada Lovelace"/>
<Avatar name="Ada Lovelace"/>
<Avatar lg name="Ada Lovelace"/>
<Avatar xl name="Ada Lovelace"/>
</Row>

Appearances and variants

The default is a neutral secondary outline circle with a thin edge. An appearance colors the initials and the icon, and filled paints the circle in the appearance color.

ALALALALAL
ALALALALAL
<Col>
<Row>
<Avatar name="Ada Lovelace"/>
<Avatar primary name="Ada Lovelace"/>
<Avatar accent name="Ada Lovelace"/>
<Avatar success name="Ada Lovelace"/>
<Avatar info name="Ada Lovelace"/>
</Row>
<Row>
<Avatar filled name="Ada Lovelace"/>
<Avatar primary filled name="Ada Lovelace"/>
<Avatar accent filled name="Ada Lovelace"/>
<Avatar success filled name="Ada Lovelace"/>
<Avatar info filled name="Ada Lovelace"/>
</Row>
</Col>

Circle or square

pill (a circle) is the default. rounded gives a square with corners a quarter of the size, which suits a team, a workspace or a company logo. sharp drops the corners.

DTDTDTBiscuit
<Row>
<Avatar name="Design Team"/>
<Avatar rounded name="Design Team"/>
<Avatar sharp name="Design Team"/>
<Avatar rounded src={photo} name="Biscuit"/>
</Row>

Icons and other content

Children take the place of the initials, so an Avatar can hold an icon or an emoji. With a name, the box still gets role="img" and the name as its label.

🎉
<Row>
<Avatar rounded accent name="Billing">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} aria-hidden="true">
<rect x="2" y="5" width="20" height="14" rx="2"/>
<path d="M2 10h20"/>
</svg>
</Avatar>
<Avatar name="Party">🎉</Avatar>
</Row>

Overlapping avatars with AvatarGroup

AvatarGroup lays avatars out in one row, each overlapping the one before it by a quarter of its size, with a ring in the surface color between them. A size on the group reaches every avatar in it, and an avatar with its own size keeps it. Give the group an aria-label, since it renders role="group".

BiscuitALATGH
<AvatarGroup aria-label="Editors">
<Avatar src={photo} name="Biscuit"/>
<Avatar name="Ada Lovelace"/>
<Avatar name="Alan Turing"/>
<Avatar name="Grace Hopper"/>
</AvatarGroup>

max shows that many avatars and counts the rest in one "+N" avatar. When only the first few people are loaded, total sets the full count, and the "+N" avatar counts against it.

BiscuitALAT+2
ALATGH+9
<Col>
<AvatarGroup lg max={3} aria-label="Reviewers">
<Avatar src={photo} name="Biscuit"/>
<Avatar name="Ada Lovelace"/>
<Avatar name="Alan Turing"/>
<Avatar name="Grace Hopper"/>
<Avatar name="Barbara Liskov"/>
</AvatarGroup>
<AvatarGroup sm total={12} aria-label="Members">
<Avatar name="Ada Lovelace"/>
<Avatar name="Alan Turing"/>
<Avatar name="Grace Hopper"/>
</AvatarGroup>
</Col>

Image attributes

imgProps reaches the inner <img>, for loading, referrerPolicy, srcSet and an onError handler of your own, which still runs before the fallback to initials.

Biscuit
<Avatar src={photo} name="Biscuit" imgProps={{ loading: 'lazy', decoding: 'async' }}/>

Customizing

Set app-wide defaults with ThemeProvider's themeDefaults. Avatar and AvatarGroup each have their own node.

ALAT
<ThemeProvider themeDefaults={{
avatar: { rounded: true, primary: true },
avatarGroup: { sm: true },
}}>
<AvatarGroup aria-label="Owners">
<Avatar name="Ada Lovelace"/>
<Avatar name="Alan Turing"/>
</AvatarGroup>
</ThemeProvider>

Frequently asked questions

What does Avatar show when the image fails to load?

The initials of name, the same as with no src at all. Avatar listens to the image's error event, and a failure before React hydrates the page is caught too. When src changes, the new image is tried again. Without a name, a failed image falls back to the person icon.

Should I pass name or alt?

Pass name. It gives the initials, and it is also the text alternative of the image, so one prop covers both. Use alt only when the image needs a different description, such as "Ada, profile photo". An avatar next to the person's name in text can drop both, since the image adds nothing to what the text already says.

How do I make an avatar a link or a button?

Wrap it in a Link or a Button with an accessible name, or pass tag to render another element. Avatar itself has no href and no button semantics, so an onClick on it is not reachable from the keyboard.

Avatar Props

PropCategoryDefaultDescription
accent

Appearance

Accent color appearance (rose)

danger

Appearance

Danger color appearance (red)

info

Appearance

Info color appearance (cyan)

inheritAppearance

Appearance

Inherit appearance from parent — suppresses own data-appearance/data-variant, uses parent's CSS variables

primary

Appearance

Primary color appearance (gray)

secondary

Appearance

✓

Secondary color appearance (gray)

success

Appearance

Success color appearance (green)

tertiary

Appearance

Tertiary color appearance

warning

Appearance

Warning color appearance (amber)

fontBlack

Font Weight

Black font weight (900) — emits font-black

fontBold

Font Weight

Bold font weight (700) — emits font-bold

fontExtrabold

Font Weight

Extra bold font weight (800) — emits font-extrabold

fontExtralight

Font Weight

Extra light font weight (200) — emits font-extralight

fontLight

Font Weight

Light font weight (300) — emits font-light

fontMedium

Font Weight

✓

Medium font weight (500) — emits font-medium

fontNormal

Font Weight

Normal font weight (400) — emits font-normal

fontSemibold

Font Weight

Semibold font weight (600) — emits font-semibold

fontThin

Font Weight

Thin font weight (100) — emits font-thin

margin

Margin

Enable margin on all sides

marginB

Margin

Enable only bottom margin

marginT

Margin

Enable only top margin

marginX

Margin

Enable only horizontal (inline) margin

marginY

Margin

Enable only vertical (block) margin

noMargin

Margin

Disable margin (reset to 0)

pill

Shape

✓

Fully rounded corners (circular)

rounded

Shape

Medium rounded corners (default)

sharp

Shape

No rounded corners (square)

noShrink

Shrink

✓

Prevent the flex item from shrinking below its content size (= shrink-0)

lg

Size

Large size

md

Size

✓

Medium size (default)

sm

Size

Small size

xl

Size

Extra large size

xs

Size

Extra small size

skeleton

Skeleton

Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too

filled

Variant

Filled variant - solid background with contrasting text color

ghost

Variant

Ghost variant - transparent background, no border, appearance-colored text, tinted hover background

outline

Variant

✓

Outline variant - transparent background with border and colored text (default)

Layout & utility props (gap, padding, hide, items, justify, ...)

Documented on Common Props.

PropCategoryDefaultDescription
border

Border

✓

Enable border on all sides

borderB

Border

Enable border on bottom

borderEnd

Border

Enable border on the inline-end side (right in LTR, left in RTL)

borderL

Border

Enable border on left

borderR

Border

Enable border on right

borderStart

Border

Enable border on the inline-start side (left in LTR, right in RTL)

borderT

Border

Enable border on top

borderX

Border

Enable border on left and right

borderY

Border

Enable border on top and bottom

noBorder

Border

Disable all borders

block

Display

Block display - takes full width, new line

contents

Display

Contents display - element's box is removed, children display as if parent didn't exist

flex

Display

Flex display - flexbox container

grid

Display

Grid display - CSS grid container

hidden

Display

Hidden display - element is not visible

inline

Display

Inline display - flows with text

inlineBlock

Display

Inline-block display - inline but with block properties

inlineFlex

Display

✓

Inline-flex display - inline flexbox container

inlineGrid

Display

Inline-grid display - inline grid container

table

Display

Table display - behaves like table element

tableCell

Display

Table-cell display - behaves like td element

desktopHide

Hide

Hide element on desktop devices and below (max-desktop: 80rem)

mobileHide

Hide

Hide element on mobile devices and below (max-mobile: 48rem)

tabletHide

Hide

Hide element on tablet devices and below (max-tablet: 64rem)

itemsBaseline

Items

Align items to baseline

itemsCenter

Items

✓

Align items to center

itemsEnd

Items

Align items to end (bottom/right)

itemsStart

Items

Align items to start (top/left)

itemsStretch

Items

Stretch items to fill container

justifyAround

Justify

Distribute items with space around them

justifyBaseline

Justify

Align items along their baseline on main axis

justifyBetween

Justify

Distribute items with space between them

justifyCenter

Justify

✓

Center items along the main axis

justifyEnd

Justify

Pack items toward the end of the main axis

justifyEvenly

Justify

Distribute items with equal space around them

justifyStart

Justify

Pack items toward the start of the main axis

justifyStretch

Justify

Stretch items to fill the main axis

overflowAuto

Overflow

Auto overflow - show scrollbars if needed

overflowClip

Overflow

Clip overflow - hard clip without scrollbars

overflowHidden

Overflow

✓

Hidden overflow - clip content without scrollbars

overflowScroll

Overflow

Scroll overflow - always show scrollbars

overflowVisible

Overflow

Visible overflow - content extends beyond bounds

overflowXAuto

Overflow

Auto overflow on X-axis only

overflowXClip

Overflow

Clip overflow on X-axis only

overflowXHidden

Overflow

Hidden overflow on X-axis only

overflowXScroll

Overflow

Scroll overflow on X-axis only

overflowXVisible

Overflow

Visible overflow on X-axis only

overflowYAuto

Overflow

Auto overflow on Y-axis only

overflowYClip

Overflow

Clip overflow on Y-axis only

overflowYHidden

Overflow

Hidden overflow on Y-axis only

overflowYScroll

Overflow

Scroll overflow on Y-axis only

overflowYVisible

Overflow

Visible overflow on Y-axis only

absolute

Position

Absolute positioning

fixed

Position

Fixed positioning

relative

Position

✓

Relative positioning

static

Position

Static positioning

sticky

Position

Sticky positioning at the top edge; set --sticky-top to stick below a fixed header

insetRing

Ring

Enable the inset ring — emits ring-inset

noInsetRing

Ring

✓

Disable the inset ring

desktopShow

Show

Show element only on desktop and below, below 1280px (hidden from 80rem up)

mobileShow

Show

Show element only on mobile, below 768px (hidden from 48rem up)

tabletShow

Show

Show element only on tablet and below, below 1024px (hidden from 64rem up)

AvatarGroup Props

PropCategoryDefaultDescription
margin

Margin

Enable margin on all sides

marginB

Margin

Enable only bottom margin

marginT

Margin

Enable only top margin

marginX

Margin

Enable only horizontal (inline) margin

marginY

Margin

Enable only vertical (block) margin

noMargin

Margin

✓

Disable margin (reset to 0)

lg

Size

Large size

md

Size

✓

Medium size (default)

sm

Size

Small size

xl

Size

Extra large size

xs

Size

Extra small size

skeleton

Skeleton

Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too

Layout & utility props (gap, padding, hide, items, justify, ...)

Documented on Common Props.

PropCategoryDefaultDescription
block

Display

Block display - takes full width, new line

contents

Display

Contents display - element's box is removed, children display as if parent didn't exist

flex

Display

✓

Flex display - flexbox container

grid

Display

Grid display - CSS grid container

hidden

Display

Hidden display - element is not visible

inline

Display

Inline display - flows with text

inlineBlock

Display

Inline-block display - inline but with block properties

inlineFlex

Display

Inline-flex display - inline flexbox container

inlineGrid

Display

Inline-grid display - inline grid container

table

Display

Table display - behaves like table element

tableCell

Display

Table-cell display - behaves like td element

column

Flex Direction

Flex direction column (vertical)

columnReverse

Flex Direction

Flex direction column-reverse

row

Flex Direction

✓

Flex direction row (horizontal)

rowReverse

Flex Direction

Flex direction row-reverse

desktopHide

Hide

Hide element on desktop devices and below (max-desktop: 80rem)

mobileHide

Hide

Hide element on mobile devices and below (max-mobile: 48rem)

tabletHide

Hide

Hide element on tablet devices and below (max-tablet: 64rem)

itemsBaseline

Items

Align items to baseline

itemsCenter

Items

✓

Align items to center

itemsEnd

Items

Align items to end (bottom/right)

itemsStart

Items

Align items to start (top/left)

itemsStretch

Items

Stretch items to fill container

justifyAround

Justify

Distribute items with space around them

justifyBaseline

Justify

Align items along their baseline on main axis

justifyBetween

Justify

Distribute items with space between them

justifyCenter

Justify

Center items along the main axis

justifyEnd

Justify

Pack items toward the end of the main axis

justifyEvenly

Justify

Distribute items with equal space around them

justifyStart

Justify

Pack items toward the start of the main axis

justifyStretch

Justify

Stretch items to fill the main axis

overflowAuto

Overflow

Auto overflow - show scrollbars if needed

overflowClip

Overflow

Clip overflow - hard clip without scrollbars

overflowHidden

Overflow

Hidden overflow - clip content without scrollbars

overflowScroll

Overflow

Scroll overflow - always show scrollbars

overflowVisible

Overflow

Visible overflow - content extends beyond bounds

overflowXAuto

Overflow

Auto overflow on X-axis only

overflowXClip

Overflow

Clip overflow on X-axis only

overflowXHidden

Overflow

Hidden overflow on X-axis only

overflowXScroll

Overflow

Scroll overflow on X-axis only

overflowXVisible

Overflow

Visible overflow on X-axis only

overflowYAuto

Overflow

Auto overflow on Y-axis only

overflowYClip

Overflow

Clip overflow on Y-axis only

overflowYHidden

Overflow

Hidden overflow on Y-axis only

overflowYScroll

Overflow

Scroll overflow on Y-axis only

overflowYVisible

Overflow

Visible overflow on Y-axis only

absolute

Position

Absolute positioning

fixed

Position

Fixed positioning

relative

Position

Relative positioning

static

Position

Static positioning

sticky

Position

Sticky positioning at the top edge; set --sticky-top to stick below a fixed header

desktopShow

Show

Show element only on desktop and below, below 1280px (hidden from 80rem up)

mobileShow

Show

Show element only on mobile, below 768px (hidden from 48rem up)

tabletShow

Show

Show element only on tablet and below, below 1024px (hidden from 64rem up)