Introduction
The Avatar component displays user profile pictures, initials, or fallback icons. It supports images, text, and icons with customizable shapes and sizes.Basic Usage
Image Avatars
Image avatars can be created by passing standardimg props via src and srcSet.
Letter Avatars
Avatars containing simple characters can be created by passing a string aschildren.
Icon Avatars
Icon avatars are created by passing an icon aschildren.
Variants
The Avatar component supports three shape variants:circular (default), rounded, and square.
Fallback
If there is an error loading the avatar image, the component falls back to an alternative in the following order:- The provided children
- The first letter of the alt text
- A generic person icon
Grouped Avatars
UseAvatarGroup to display multiple avatars as a stack.
Props
Avatar Props
| Prop | Type | Default | Description |
|---|---|---|---|
alt | string | - | Used in combination with src or srcSet to provide an alt attribute for the rendered img element. |
children | node | - | Used to render icon or text elements inside the Avatar if src is not set. |
classes | object | - | Override or extend the styles applied to the component. |
imgProps | object | - | Attributes applied to the img element if the component is used to display an image. Deprecated: Use slotProps.img instead. |
sizes | string | - | The sizes attribute for the img element. |
src | string | - | The src attribute for the img element. |
srcSet | string | - | The srcSet attribute for the img element. Use this for responsive image display. |
sx | SxProps<Theme> | - | The system prop for defining CSS overrides and additional styles. |
variant | 'circular' | 'rounded' | 'square' | 'circular' | The shape of the avatar. |
Slots
| Slot | Type | Default | Description |
|---|---|---|---|
root | ElementType | 'div' | The component that renders the root slot. |
img | ElementType | 'img' | The component that renders the img slot. |
fallback | ElementType | Person icon | The component that renders the fallback slot. |
CSS Classes
The following CSS classes are available for customization:.MuiAvatar-root- Styles applied to the root element..MuiAvatar-colorDefault- Styles applied to the root element if no src or children are provided..MuiAvatar-circular- Styles applied to the root element ifvariant="circular"..MuiAvatar-rounded- Styles applied to the root element ifvariant="rounded"..MuiAvatar-square- Styles applied to the root element ifvariant="square"..MuiAvatar-img- Styles applied to the img element..MuiAvatar-fallback- Styles applied to the fallback icon.
Accessibility
Always provide meaningfulalt text for image avatars to ensure screen reader users can understand the content: