Avatar

A graphical representation of the user, often used in profile sections.

Loading...

Anatomy

<Avatar.Root>
  <Avatar.Fallback />
  <Avatar.Image />
</Avatar.Root>

Examples

Basic

Display a user's profile image with a fallback.

Events

Use onStatusChange to listen for loading state changes.

Root Provider

Use RootProvider with the useAvatar hook to access the state and methods from outside the component.

AvatarStack

Stack the first 3 avatars. The +N overflow is a Menu.Trigger that lists everyone else.

Guides

Next.js Image

Render the Image component from next/image inside the avatar.

import { Avatar, useAvatarContext } from '@ark-ui/react/avatar'
import { getImageProps, type ImageProps } from 'next/image'

const AvatarNextImage = (props: ImageProps) => {
  const avatar = useAvatarContext()

  const { hidden, ...arkImageProps } = avatar.getImageProps()
  const nextImage = getImageProps(props)

  return (
    <img
      {...arkImageProps}
      {...nextImage.props}
      style={{
        ...props.style,
        // use visibility instead
        visibility: hidden ? 'hidden' : 'visible',
      }}
    />
  )
}

const Demo = () => {
  return (
    <Avatar.Root>
      <Avatar.Fallback>JD</Avatar.Fallback>
      <AvatarNextImage src="..." alt="" width={80} height={80} />
    </Avatar.Root>
  )
}

See this GitHub Discussion for details.

API Reference

Props

Root

Defines the <span> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
ids
ElementIds

The ids of the elements in the avatar. Useful for composition.

onStatusChange
(details: StatusChangeDetails) => void

Functional called when the image loading status changes.

render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-avatar-root]<uid>
[data-status]

Fallback

Defines the <span> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-avatar-fallback]<uid>
[data-state]"hidden" | "visible"

Image

Defines the <img> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-avatar-image]<uid>
[data-state]"visible" | "hidden"

RootProvider

Defines the <span> element.

AttributeDefaultType
value
UseAvatarReturn

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

Context

API

PropertyType
status
LoadStatus

The current image loading status.

loaded
boolean

Whether the image is loaded.

setLoaded
VoidFunction

Function to set loaded state.

setError
VoidFunction

Function to set error state.

getRootState
() => RootState

Returns the state of the root.