Color Schemes for Avatar
are not implemented in the default theme. You can extend the themeto implement them.
ChatGPT UI Avatar - Horizon AI Template
The Avatar
component is used to represent a user, and displays the profile
picture, initials or fallback icon.
Import#
Chakra UI exports 3 avatar-related components:
Avatar
: The image that represents the user.AvatarBadge
: A wrapper that displays its content on the right corner of the avatar.AvatarGroup
: A wrapper to stack multiple Avatars together.
import { Avatar, AvatarBadge, AvatarGroup } from "@chakra-ui/react"
Usage#
<Wrap><WrapItem><Avatarname="Might Guy"src="https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1700&q=80"/></WrapItem><WrapItem><Avatarname="Sakura Haruno"src="https://images.unsplash.com/photo-1438761681033-6461ffad8d80?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3900&q=80"/></WrapItem><WrapItem><Avatarname="Kakashi Hatake"src="https://images.unsplash.com/photo-1542847970-584270eb111b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1233&q=80"/></WrapItem><WrapItem><Avatarname="Naruto Uzumaki"src="https://images.unsplash.com/photo-1599566150163-29194dcaad36?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/></WrapItem><WrapItem><Avatarname="Sasuke Uchiha"src="https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixid=MnwxMjA3fDB8MHxzZWFyY2h8N3x8YXZhdGFyfGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60"/></WrapItem><WrapItem><Avatarname="Isshiki Otsutsuki"src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/></WrapItem><WrapItem><Avatarname="Kawaki"src="https://images.unsplash.com/photo-1626586066636-a1523dd2141b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/></WrapItem></Wrap>
<Wrap><WrapItem><Avatarname="Might Guy"src="https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1700&q=80"/></WrapItem><WrapItem><Avatarname="Sakura Haruno"src="https://images.unsplash.com/photo-1438761681033-6461ffad8d80?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3900&q=80"/></WrapItem><WrapItem><Avatarname="Kakashi Hatake"src="https://images.unsplash.com/photo-1542847970-584270eb111b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1233&q=80"/></WrapItem><WrapItem><Avatarname="Naruto Uzumaki"src="https://images.unsplash.com/photo-1599566150163-29194dcaad36?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/></WrapItem><WrapItem><Avatarname="Sasuke Uchiha"src="https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixid=MnwxMjA3fDB8MHxzZWFyY2h8N3x8YXZhdGFyfGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60"/></WrapItem><WrapItem><Avatarname="Isshiki Otsutsuki"src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/></WrapItem><WrapItem><Avatarname="Kawaki"src="https://images.unsplash.com/photo-1626586066636-a1523dd2141b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/></WrapItem></Wrap>
Avatar Sizes#
The Avatar
component comes in 7 sizes.
<Wrap><WrapItem><Avatarsize="2xs"name="Might Guy"src="https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1700&q=80"/></WrapItem><WrapItem><Avatarsize="xs"name="Sakura Haruno"src="https://images.unsplash.com/photo-1438761681033-6461ffad8d80?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3900&q=80"/>{" "}</WrapItem><WrapItem><Avatarsize="sm"name="Kakashi Hatake"src="https://images.unsplash.com/photo-1542847970-584270eb111b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1233&q=80"/>{" "}</WrapItem><WrapItem><Avatarsize="md"name="Naruto Uzumaki"src="https://images.unsplash.com/photo-1599566150163-29194dcaad36?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/>{" "}</WrapItem><WrapItem><Avatar size="lg" name="Sasuke Uchiha" src="" />{" "}</WrapItem><WrapItem><Avatarsize="xl"name="Isshiki Otsutsuki"src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/>{" "}</WrapItem><WrapItem><Avatar size="2xl" name="Kawaki" src="" />{" "}</WrapItem></Wrap>
<Wrap><WrapItem><Avatarsize="2xs"name="Might Guy"src="https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1700&q=80"/></WrapItem><WrapItem><Avatarsize="xs"name="Sakura Haruno"src="https://images.unsplash.com/photo-1438761681033-6461ffad8d80?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=3900&q=80"/>{" "}</WrapItem><WrapItem><Avatarsize="sm"name="Kakashi Hatake"src="https://images.unsplash.com/photo-1542847970-584270eb111b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1233&q=80"/>{" "}</WrapItem><WrapItem><Avatarsize="md"name="Naruto Uzumaki"src="https://images.unsplash.com/photo-1599566150163-29194dcaad36?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/>{" "}</WrapItem><WrapItem><Avatar size="lg" name="Sasuke Uchiha" src="" />{" "}</WrapItem><WrapItem><Avatarsize="xl"name="Isshiki Otsutsuki"src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/>{" "}</WrapItem><WrapItem><Avatar size="2xl" name="Kawaki" src="" />{" "}</WrapItem></Wrap>
Avatar Fallbacks#
If there is an error loading the src
of the avatar, there are 2 fallbacks:
- If there's a
name
prop, we use it to generate the initials and a random, accessible background color. - If there's no
name
prop, we use a default avatar.
<Stack direction="row"><Avatar name="Oshigaki Kisame" src="https://bit.ly/broken-link" /><Avatarname="Sasuke Uchiha"src="https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixid=MnwxMjA3fDB8MHxzZWFyY2h8N3x8YXZhdGFyfGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60https://bit.ly/broken-link"/><Avatar src="https://bit.ly/broken-link" /></Stack>
<Stack direction="row"><Avatar name="Oshigaki Kisame" src="https://bit.ly/broken-link" /><Avatarname="Sasuke Uchiha"src="https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixid=MnwxMjA3fDB8MHxzZWFyY2h8N3x8YXZhdGFyfGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60https://bit.ly/broken-link"/><Avatar src="https://bit.ly/broken-link" /></Stack>
Customize the fallback avatar#
You can customize the background color and icon of the fallback avatar icon to match your design requirements.
- To update the background, pass the usual
bg
prop. - To update the icon svg, pass the
icon
prop.
<AvatarGroup spacing="1rem"><Avatar bg="red.500" icon={<AiOutlineUser fontSize="1.5rem" />} /><Avatar bg="brand.500" /></AvatarGroup>
<AvatarGroup spacing="1rem"><Avatar bg="red.500" icon={<AiOutlineUser fontSize="1.5rem" />} /><Avatar bg="brand.500" /></AvatarGroup>
Avatar with badge#
In some products, you might need to show a badge on the right corner of the avatar. We call this a badge. Here's an example that shows if the user is online:
<Stack direction="row" spacing={4}><Avatar><AvatarBadge boxSize="1.25em" bg="green.500" /></Avatar>{/* You can also change the borderColor and bg of the badge */}<Avatar><AvatarBadge borderColor="papayawhip" bg="tomato" boxSize="1.25em" /></Avatar></Stack>
<Stack direction="row" spacing={4}><Avatar><AvatarBadge boxSize="1.25em" bg="green.500" /></Avatar>{/* You can also change the borderColor and bg of the badge */}<Avatar><AvatarBadge borderColor="papayawhip" bg="tomato" boxSize="1.25em" /></Avatar></Stack>
Note the use of
em
for the size of theAvatarBadge
. This is useful to size the badge relative to the avatar font size.
AvatarGroup#
In some cases, you might need to stack avatars as a group. Use the AvatarGroup
component.
- To limit the amount of avatars to show, use the
max
prop. It'll truncate the avatars and show a "+X" label (where X is the remaining avatars). - To size all the avatars equally, pass the
size
prop. - To adjust the spacing between the avatars, pass the
spacing
prop.
<AvatarGroup size="md" max={2}><Avatarname="Naruto Uzumaki"src="https://images.unsplash.com/photo-1599566150163-29194dcaad36?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/><Avatarname="Kawaki"src="https://images.unsplash.com/photo-1626586066636-a1523dd2141b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/><Avatarname="Kakashi Hatake"src="https://images.unsplash.com/photo-1542847970-584270eb111b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1233&q=80"/><Avatarname="Sasuke Uchiha"src="https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixid=MnwxMjA3fDB8MHxzZWFyY2h8N3x8YXZhdGFyfGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60"/><Avatarname="Isshiki Otsutsuki"src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/></AvatarGroup>
<AvatarGroup size="md" max={2}><Avatarname="Naruto Uzumaki"src="https://images.unsplash.com/photo-1599566150163-29194dcaad36?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/><Avatarname="Kawaki"src="https://images.unsplash.com/photo-1626586066636-a1523dd2141b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/><Avatarname="Kakashi Hatake"src="https://images.unsplash.com/photo-1542847970-584270eb111b?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1233&q=80"/><Avatarname="Sasuke Uchiha"src="https://images.unsplash.com/photo-1570295999919-56ceb5ecca61?ixid=MnwxMjA3fDB8MHxzZWFyY2h8N3x8YXZhdGFyfGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60"/><Avatarname="Isshiki Otsutsuki"src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1234&q=80"/></AvatarGroup>
Changing the initials logic#
Added getInitials
prop to allow users to manage how initials are generated
from name. By default we merge the first characters of each word in the name
prop.
Props#
Avatar Props#
Avatar
composes the Box
component so you can pass all its props. These are
props specific to the Avatar
component:
colorScheme
colorScheme
"brand" | "whiteAlpha" | "blackAlpha" | "gray" | "red" | "orange" | "yellow" | "green" | "teal" | "blue" | "cyan" | "purple" | "pink" | "linkedin" | "facebook" | ... 4 more ...
getInitials
getInitials
Function to get the initials to display
((name: string) => string)
icon
icon
The default avatar used as fallback when name
, and src
is not specified.
React.ReactElement
iconLabel
iconLabel
string
loading
loading
Defines loading strategy
"eager" | "lazy"
name
name
The name of the person in the avatar.
- if src
has loaded, the name will be used as the alt
attribute of the img
- If src
is not loaded, the name will be used to create the initials
string
onError
onError
Function called when image failed to load
(() => void)
showBorder
showBorder
If true
, the Avatar
will show a border around it.
Best for a group of avatars
boolean
size
size
"sm" | "md" | "lg" | "xl" | "2xl" | "full" | "2xs" | "xs"
"md"
src
src
The image url of the Avatar
string
srcSet
srcSet
List of sources to use for different screen resolutions
string
variant
variant
Variants for Avatar
are not implemented in the default theme. You can extend the themeto implement them.
string
Avatar Group Props#
AvatarGroup
composes the Box
component so you can pass all its props. These
are props specific to the AvatarGroup
component:
children
required
children
required
The children of the avatar group.
Ideally should be Avatar
and MoreIndicator
components
ReactNode
colorScheme
colorScheme
Color Schemes for AvatarGroup
are not implemented in the default theme. You can extend the themeto implement them.
"brand" | "whiteAlpha" | "blackAlpha" | "gray" | "red" | "orange" | "yellow" | "green" | "teal" | "blue" | "cyan" | "purple" | "pink" | "linkedin" | "facebook" | ... 4 more ...
max
max
The maximum number of visible avatars
number
size
size
"sm" | "md" | "lg" | "xl" | "2xl" | "full" | "2xs" | "xs"
spacing
spacing
The space between the avatars in the group.
SystemProps["margin"]
variant
variant
Variants for AvatarGroup
are not implemented in the default theme. You can extend the themeto implement them.
string