Avatar
An easily stylable avatar component.
View as MarkdownAnatomy
Import the component and assemble its parts:
import { Avatar } from '@base-ui/react/avatar';
<Avatar.Root>
<Avatar.Image src="" />
<Avatar.Fallback>LT</Avatar.Fallback>
</Avatar.Root>API reference
Root
Displays a user’s profile picture, initials, or fallback icon.
Renders a <span> element.
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Avatar.Root.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Avatar.Root.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Avatar.Root.State, ) => ReactElement) | undefined
Additional Types
Avatar.Root.Props
Re-Export of Root props as AvatarRootProps
Avatar.Root.State
type AvatarRootState = { imageLoadingStatus: ImageLoadingStatus };Image
The image to be displayed in the avatar.
Renders an <img> element.
onLoadingStatusChangefunction—
function- Description
Callback fired when the loading status changes.
- Type
((status: ImageLoadingStatus) => void) | undefined
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Avatar.Root.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Avatar.Root.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Avatar.Root.State, ) => ReactElement) | undefined
Additional Types
Avatar.Image.Props
Re-Export of Image props as AvatarImageProps
Fallback
Rendered when the image fails to load or when no image is provided.
Renders a <span> element.
delaynumber—
number- Name
- Description
How long to wait before showing the fallback. Specified in milliseconds.
- Type
number | undefined
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Avatar.Root.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Avatar.Root.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Avatar.Root.State, ) => ReactElement) | undefined
Additional Types
Avatar.Fallback.Props
Re-Export of Fallback props as AvatarFallbackProps