Introducing PrimeReact v11-alpha 🎉Discover Now

Avatar

An unstyled avatar component with compound composition and group support.

Build fully custom avatar elements with complete control over layout and styling.

AB
CD
+3
basic-demo

Pre-styled Versions

Choose a pre-styled library to use Avatar with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with three sub-components: Root, Image, Fallback
  • AvatarGroup for visually grouping multiple avatars
  • Automatic image load detection — Image renders only after successful load, Fallback renders otherwise
  • Configurable delayDuration for delayed image reveal

Usage#

import { Avatar } from 'primereact/avatar';
import { AvatarGroup } from 'primereact/avatargroup';
<AvatarGroup>
    <Avatar.Root>
        <Avatar.Image src="..." />
        <Avatar.Fallback></Avatar.Fallback>
    </Avatar.Root>
</AvatarGroup>

Behavior#

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element.

<Avatar.Root as="span">
    <Avatar.Image src="..." />
    <Avatar.Fallback as="div">AB</Avatar.Fallback>
</Avatar.Root>

Default elements: Root=div, Image=img, Fallback=span.

Render Function Children#

Avatar.Fallback accepts a render function as children, providing access to the component instance.

<Avatar.Fallback>{(instance) => <span>{instance.avatar?.state.load ? 'Loaded' : 'Fallback'}</span>}</Avatar.Fallback>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

A
/* Select a part to see its CSS selector for custom styling */

API#

AvatarRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: AvatarRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: AvatarRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceAvatarRootInstance—
The instance to pass to the component.
ptSafeRecord<AvatarRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: AvatarRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
delayDurationnumber—
The delay duration of the avatar.
size"large" | "normal" | "xlarge"normal
Defines the size of the avatar.
shape"circle" | "square"square
Defines the shape of the avatar.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"avatar"
data-part"root"

Defines passthrough(pt) options of AvatarRoot component.

labeltypedescription
rootAvatarRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
fallbackAvatarRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the fallback's DOM element.
imageAvatarRootPassThroughType<ImgHTMLAttributes<HTMLImageElement>>Used to pass attributes to the image's DOM element.

AvatarImage#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: AvatarImageInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: AvatarImageInstance) => string)—
The class name to apply to the component.
asReactNode—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceAvatarImageInstance—
The instance to pass to the component.
ptSafeRecord<AvatarImagePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: AvatarImageInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
srcstringundefined
Specifies the path to the image to display.
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of AvatarImage component.

labeltypedescription
rootAvatarImagePassThroughType<ImgHTMLAttributes<HTMLImageElement>>Used to pass attributes to the root's DOM element.

AvatarFallback#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: AvatarFallbackInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: AvatarFallbackInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceAvatarFallbackInstance—
The instance to pass to the component.
ptSafeRecord<AvatarFallbackPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: AvatarFallbackInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of AvatarFallback component.

labeltypedescription
rootAvatarFallbackPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the root's DOM element.

AvatarGroup#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: AvatarGroupInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: AvatarGroupInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceAvatarGroupInstance—
The instance to pass to the component.
ptSafeRecord<AvatarGroupPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: AvatarGroupInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"avatargroup"
data-part"root"

Defines passthrough(pt) options of AvatarGroup component.

labeltypedescription
rootAvatarGroupPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

Accessibility#

Screen Reader#

Avatar does not include any roles and attributes by default. Any attribute is passed to the root element so a role like img along with aria-labelledby or aria-label can be added to describe the component. In case avatars need to be tabbable, tabIndex can be added to implement custom key handlers.

Keyboard Support#

Component does not include any interactive elements.