Props
Usage guidelines
- To reflect a person, company or brand within the product.
- To represent a group of people, companies and/or brands. Use AvatarGroup instead.
Best Practices
Use the default alternative if no image source is available. This will be the first character of the provided name.
Use alternative graphics or icons
Use round Avatars in the appropriate size for your need. Learn more about avatar sizing.
Scale or change the shape of Avatar. Instead use the designated Avatar sizes and style.
Use Avatar to represent a person, organization or group (Avatar Group).
Use Avatar to represent metaphorical ideas, like a Board. Instead, consider an icon or the appropriate interactive component.
Use the collaborator’s name nearby or in an alternative view if possible.
Place elements like washes, text or icons over Avatars.
Accessibility
The avatar should have a text equivalent. Use the accessibilityLabel
prop to ensure there is a text description for the image. The VoiceOver description will default to the name
prop if accessibilityLabel
is not provided.
Make sure that the alternative text properly describes the information and function of the avatar image(s). Depending on the situation, it may be helpful to state the collaborator or company name and/or their verification status.
Localization
Be sure to localize any content in the accessibilityLabel
that isn’t a name.
Variants
Fixed sizes
There are 5 sizes available for Avatar. For certain designs you may need a container-based size.
import {} from 'react'; import { Flex, Avatar } from 'gestalt'; export default function Example() { return ( <Flex gap={4} wrap height="100%" width="100%" alignItems="center" justifyContent="center" > <Avatar size="xs" src="https://i.ibb.co/ZfCZrY8/keerthi.jpg" name="Keerthi" /> <Avatar size="sm" src="https://i.ibb.co/ZfCZrY8/keerthi.jpg" name="Keerthi" /> <Avatar size="md" src="https://i.ibb.co/ZfCZrY8/keerthi.jpg" name="Keerthi" /> <Avatar size="lg" src="https://i.ibb.co/ZfCZrY8/keerthi.jpg" name="Keerthi" /> <Avatar size="xl" src="https://i.ibb.co/ZfCZrY8/keerthi.jpg" name="Keerthi" /> </Flex> ); }
Container-based sizes
Avatars without a size
prop will expand to fit the width of their parent container. A common use case is to achieve column-based sizing.
Resize the browser to see these Avatar change to match the width of the Column
they have been placed in.
import {} from 'react'; import { Flex, Avatar, Box } from 'gestalt'; export default function Example() { return ( <Box width="100%" maxWidth={900}> <Flex> <Box width={40}> <Avatar name="Julia" /> </Box> <Box column={2}> <Avatar name="Julia" /> </Box> <Box column={4}> <Avatar name="Keerthi" src="https://i.ibb.co/ZfCZrY8/keerthi.jpg" /> </Box> </Flex> </Box> ); }
Without an image
If there is no image source provided to the Avatar, the first character of
the name provided will be used as a placeholder.
import {} from 'react'; import { Avatar, Flex } from 'gestalt'; export default function Example() { return ( <Flex height="100%" width="100%" alignItems="center" justifyContent="center" > <Avatar size="lg" name="Keerthi" /> </Flex> ); }
Verified
For users with verified accounts, use the verified
prop to add a checkmark. Be sure to update the accessibilityLabel
to include this information as well.
import {} from 'react'; import { Flex, Avatar } from 'gestalt'; export default function Example() { return ( <Flex height="100%" width="100%" alignItems="center" justifyContent="center" > <Avatar name="Shanice" accessibilityLabel="Shanice, Verified account" size="lg" src="https://i.ibb.co/7tGKGvb/shanice.jpg" verified /> </Flex> ); }
Component quality checklist
Quality item | Status | Status description |
---|---|---|
Figma Library | Ready | Component is available in Figma across all platforms. |
Responsive Web | Ready | Component is available in code for web and mobile web. |
iOS | Component is not currently available in code for iOS. | |
Android | Planned | Component is slotted to be built for Android. |
Related
AvatarGroup
AvatarGroup is the ideal component in cases where multiple people/brands need to be displayed.