apps/www/content/docs/components/avatar.mdx
import { Avatar, AvatarGroup } from "@chakra-ui/react"
<AvatarGroup>
<Avatar.Root>
<Avatar.Fallback />
<Avatar.Image />
</Avatar.Root>
</AvatarGroup>
:::info
If you prefer a closed component composition, check out the snippet below.
:::
Use the size prop to change the size of the avatar
Use the variant prop to change the variant of the avatar
Use the shape prop to change the shape of the avatar, from rounded to
square
Use the colorPalette prop to change the color of the avatar
Render Avatar.Icon as the fallback when the name is not provided or when the
image fails to load.
Combine the colorPalette prop with some custom logic to dynamically change the
color of the avatar
Use the outline* props to add a ring around the avatar
Use the Group component to group multiple avatars together
When using the AvatarGroup component, you can use the stacking prop to
change the stacking order of the avatars
Here's an example of how to use the Avatar component to display a user
persona.
Show a badge on the right corner of the avatar by composing the Float and
Circle components
Here's an example of how to handle an overflow of avatars by composing the
Menu and Avatar components.
Here's an example of how to compose the avatar with Next.js Image.
import { getImageProps } from "next/image"
function Demo() {
const imageProps = getImageProps({
src: "/image.png",
})
return (
<Avatar.Root>
<Avatar.Fallback name="Segun Adebayo" />
<Avatar.Image {...imageProps} />
</Avatar.Root>
)
}
An alternative way to access the avatar state and methods is to use the
RootProvider component and the useAvatar store hook.
Here's how to setup the Avatar for a closed component composition.
<ExampleCode name="avatar-closed-component" />If you want to automatically add the closed component to your project, run the command:
npx @chakra-ui/cli snippet add avatar
Explore the Avatar component parts interactively. Click on parts in the
sidebar to highlight them in the preview.