Design system
Docs
Primitives

Avatar

Image with initials fallback in four sizes, two shapes, and five tones

Import
import { Avatar, AvatarFallback, AvatarImage } from "@nyte-ai/ui";

Implemented in packages/ui/src/components/ui/avatar.tsx, wrapping @base-ui/react/avatar (no dedicated headless subpath; the styled wrapper is the only export).

Usage

  • Always include AvatarFallback. The image can fail, and the fallback is what a screen reader user and a slow network both get.
  • Fallback text is two characters. The font sizes are tuned for that and nothing longer fits at xs.
  • tone is for identity (a participant, an agent), not for status. Do not use green to mean online.
  • AvatarImage needs alt. If the avatar is decorative beside the participant's name, alt="".

Anatomy

<Avatar>
  <AvatarImage />
  <AvatarFallback />
</Avatar>

Avatar renders a <span> with data-slot="avatar", data-size, and data-tone. Image and fallback set data-slot="avatar-image" and data-slot="avatar-fallback".

Examples

Sizes and shapes

ILNYSMXS
<Avatar size="lg">
  <AvatarImage src="…" alt="interfaces-lab" />
  <AvatarFallback>IL</AvatarFallback>
</Avatar>
<Avatar size="md"><AvatarFallback>NY</AvatarFallback></Avatar>
<Avatar size="sm" shape="rounded"><AvatarFallback>SM</AvatarFallback></Avatar>
<Avatar size="xs" shape="rounded"><AvatarFallback>XS</AvatarFallback></Avatar>

Tones

NEORBLVIGR

Props

Avatar

PropTypeDefaultDescription
size"xs" | "sm" | "md" | "lg""md"20, 24, 28, or 36px.
shape"circle" | "rounded""circle"Pill radius or --nyte-radius-avatar (42%).
tone"neutral" | "orange" | "blue" | "violet" | "green""neutral"Background and foreground pair.
className, style, xstylesee Theming

Displays a user's profile picture, initials, or fallback icon. Renders a <span> element.

Root Props:

PropTypeDefaultDescription
classNamestring | ((state: Avatar.Root.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Avatar.Root.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Avatar.Root.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

AvatarImage

The image to be displayed in the avatar. Renders an <img> element.

Image Props:

PropTypeDefaultDescription
onLoadingStatusChange((status: ImageLoadingStatus) => void)-Callback fired when the loading status changes.
classNamestring | ((state: Avatar.Image.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Avatar.Image.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
keepMountedbooleanfalseWhether the image element stays mounted and loads in place instead of being preloaded. Supports loading="lazy" and optimized image components such as next/image.
renderReactElement | ((props: React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, state: Avatar.Image.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Image Data Attributes:

AttributeTypeDescription
data-error-Present when the image failed to load.
data-loading-Present while the image is loading.
data-starting-style-Present when the image begins animating in.
data-ending-style-Present when the image is animating out.

AvatarFallback

Rendered when the image fails to load or when no image is provided. Renders a <span> element.

Fallback Props:

PropTypeDefaultDescription
delaynumber0How long to wait before showing the fallback. Specified in milliseconds.
classNamestring | ((state: Avatar.Fallback.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Avatar.Fallback.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Avatar.Fallback.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Accessibility

  • The root is a <span>; it has no role. Meaning comes from the image's alt or from the text around it.
  • Base UI tracks image loading status and swaps to the fallback on error or while loading; delay on the fallback avoids a flash for fast loads.

Styling

TokenRole
--nyte-avatar-size-*, --nyte-avatar-font-*Per-size box and fallback font
--nyte-avatar-ring-width0.5px border in --nyte-color-border
--nyte-color-avatar-*-background / -foregroundPer-tone pair
--nyte-radius-avatar, --nyte-radius-pillShapes
--nyte-font-weight-semiboldFallback weight