Skip to content

Avatar

Show a person or team’s image, with initials while it loads or if it fails.

import { Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage } from '@youj/react'

Installation & usage

npm i @youj/react

For an app already set up with npx @youj/cli init, which installs the peers (@youj/core, @youj/motion, motion and Base UI) and wires the provider. New app? Start at Installation.

Use Avatar for an author, assignee or member. Show the person’s name alongside it when space allows. For a company or project, consider an icon or logo instead of initials.

import { Avatar, AvatarFallback, AvatarImage } from '@youj/react'

export function Author() {
  return (
    <Avatar>
      <AvatarImage src="/people/ana.jpg" alt="Ana Lima" />
      <AvatarFallback>AL</AvatarFallback>
    </Avatar>
  )
}

The fallback shows until the image has actually loaded, and stays if the image fails, so there's never a broken-image frame. When the image arrives, it fades in over the muted disc.

Reference

Propssize (1)

Props

Avatar

Avatar props
PropType
size'sm' | 'default' | 'lg'

default 'default'

'default'

AvatarImage

AvatarImage adds no props of its own. They pass through to AvatarPrimitive.Image.Props.

AvatarImage takes an image's src and alt, and Base UI's onLoadingStatusChange. AvatarFallback takes Base UI's delay, in milliseconds, to hold the initials back briefly on fast connections, and colorSeed to tint them with a chart colour picked from the seed. AvatarBadge, AvatarGroup and AvatarGroupCount render plain elements and take their usual attributes.

MotionImage in · reduced motion

Motion

Motion tokens
MomentTokens
Image infades in over the fallback once loaded
duration.baseease.standard

220ms · cubic-bezier(0.2, 0, 0, 1)

220mscubic-bezier(0.2, 0, 0, 1)

Reduced motion

The image replaces the fallback at once.

Reduced motion

A loaded image replaces the initials at once instead of fading in. Nothing else about the avatar moves.

AccessibilityARIA, announcements

Accessibility

  • An avatar next to a visible name is decorative. Mark it aria-hidden and give its image an empty alt, as in the demo, so the name isn't read twice.
  • An avatar on its own, such as one in a stack, needs the person's name. Put it in the image's alt, and give the fallback role="img" and an aria-label with the same name, so it reads the same before the image loads or if it fails.
  • The status dot is color only. Say the status in text nearby, or include it in the name, as in "Priya Raman, online".
  • Give the group count words for screen readers, such as "and 4 more", rather than "+4".