Avatar
Avatar is a visual representation of a user's profile and identity.
Avatar (Main) vs. Avatar (Preview)
We recommend you use the Avatar in the Preview package (@workday/canvas-kit-preview-react)
documented here on this page. The Avatar in the Main package (@workday/canvas-kit-react) will
eventually be replaced with the Avatar in the Preview package.
Anatomy
![]()
- Background: A randomly selected fill color for the initial-based variant.
- Initials: The first letters of a user’s first and last names in a darker gradient of fill color.
- Image: A user-uploaded image of themselves.
Usage Guidance
When to Use
- Use Avatars to provide a user with a stronger identity or when an access point into their profile provides reasonable benefit.
When to Use Something Else
- If the data is not a user, and a symbolic representation is needed, use an icon component instead.
Avatars vary on the basis of version, sizing, background, and default color.
Version
Avatars default to their initial-based version unless a user manually uploads a profile photo. The lettering inside the Avatar is based on the two letter English initials of the Western equivalent of a user name.
![]()
Sizing
Avatars should feel appropriately sized based on their importance and nearby content. They vary on a scale from XXS to XXL to accommodate an array of different possible use cases:
- XXS: 24 x 24. Please note that it is recommended to use a larger size than XXS for all uses outside of pills.
![]()
![]()
- XS: 32 x 32
- S: 40 x 40
- M: 48 x 48
- L: 72 x 72
- XL: 96 x 96
- XXL: 120 x 120
Regardless of Avatar sizing, all tap targets are 48x48 or larger.
![]()
Color
Initial-based avatars are randomly assigned a gender neutral and contrast friendly color on a per-user basis.
![]()
Examples
Basic Example
The most basic usage requires only a name prop. The component automatically extracts and displays
the initials. If you want to display a different set of initials, you can use the preferredInitials prop.
import {Avatar} from '@workday/canvas-kit-preview-react/avatar';
export default () => {
return <Avatar name="John Doe" />;
};
Image Avatar
You can display a profile image by providing the url prop.
Note: The
urland thenameprop is required for the image avatar. Thenameis used for thealtattribute on the image.
Image Fallback Behavior
The Avatar component includes intelligent fallback handling:
- While the image loads, the user’s initials are displayed using the
nameprop - If the image fails to load, initials remain visible
- The
nameprop serves as both the alt text and fallback content
import {Avatar} from '@workday/canvas-kit-preview-react/avatar';
export default () => {
return (
<Avatar
name="Happy Doggo"
url={'https://picsum.photos/id/237/300/200'}
objectFit="cover"
size="medium"
/>
);
};
Sizes
The Avatar component supports the following sizes:
extraExtraSmallis 24px x 24pxextraSmallis 32px x 32pxsmallis 40px x 40pxmediumis 48px x 48pxlargeis 72px x 72pxextraLargeis 96px x 96pxextraExtraLargeis 120px x 120px
import {Avatar} from '@workday/canvas-kit-preview-react/avatar';
import {createStyles} from '@workday/canvas-kit-styling';
import {system} from '@workday/canvas-tokens-web';
const containerStyles = createStyles({
display: 'inline-flex',
gap: system.space.x2,
});
export default () => {
return (
<div className={containerStyles}>
<Avatar name="John Doe" size="extraExtraSmall" />
<Avatar name="Logan McNeil" size="extraSmall" />
<Avatar name="Wonder Woman" size="small" />
<Avatar name="Iron Man" size="medium" />
<Avatar name="Peter Parker" size="large" />
<Avatar name="Bruce Banner" size="extraLarge" />
<Avatar name="Elektra" size="extraExtraLarge" />
</div>
);
};
Variants
Choose from four predefined color schemes:
import {Avatar} from '@workday/canvas-kit-preview-react/avatar';
import {createStyles} from '@workday/canvas-kit-styling';
import {system} from '@workday/canvas-tokens-web';
const containerStyles = createStyles({
display: 'inline-flex',
gap: system.space.x2,
});
export default () => {
return (
<div className={containerStyles}>
<Avatar name="John Doe" variant="blue" />
<Avatar name="Logan McNeil" variant="amber" />
<Avatar name="Wonder Woman" variant="teal" />
<Avatar name="Elektra" variant="purple" />
</div>
);
};
Advanced Custom Component
For complete control over styling and behavior, use the BaseAvatar component:
import {BaseAvatar} from '@workday/canvas-kit-preview-react/avatar';
import {createStyles, px2rem} from '@workday/canvas-kit-styling';
import {base} from '@workday/canvas-tokens-web';
const customStyles = createStyles({
cursor: 'pointer',
backgroundColor: base.magenta300,
color: base.magenta700,
borderRadius: '50%',
border: 'none',
padding: '0',
margin: '0',
display: 'flex',
alignItems: 'center',
span: {
cursor: 'pointer',
},
});
export default () => {
return (
<BaseAvatar
size={px2rem(56)}
cs={customStyles}
as="button"
onClick={() => console.log('clicked')}
>
<BaseAvatar.Name name="John Doe Jane" />
</BaseAvatar>
);
};
Accessibility
If the Avatar is purely decorative, you can set the isDecorative prop to true to prevent the name prop from being forwarded to the alt attribute of the image.
import {Avatar} from '@workday/canvas-kit-preview-react/avatar';
// @ts-ignore
import nicholasAvatar from './nicholas-avatar.jpg';
import {createStyles} from '@workday/canvas-kit-styling';
import {Text} from '@workday/canvas-kit-react/text';
import {system} from '@workday/canvas-tokens-web';
const containerStyles = createStyles({
display: 'inline-flex',
gap: system.space.x2,
alignItems: 'center',
});
export default () => {
return (
<div className={containerStyles}>
<Avatar
name="Nicholas Smith"
isDecorative
url={nicholasAvatar}
objectFit="cover"
size="small"
/>
<Text>Nicholas Smith</Text>
</div>
);
};
Component API
Avatar
Props
Props extend from div. Changing the as prop will change the element interface.
| Name | Type | Description | Default |
|---|---|---|---|
url | string | The URL of the user's photo. For best fit, use square images. | |
objectFit | Property.ObjectFit | An objectFit property that can customize how to resize your image to fit its container. | 'contain' |
isDecorative | boolean | If true, the Avatar won't forward the | |
children | ReactNode | Children of the BaseAvatar. | |
variant | | The variant of the Avatar. | 'blue' |
size | | The size of the Avatar.
| 'medium' |
cs | | The | |
name | string | The alt text of the Avatar image. This prop is also used for the initials. The first letter of the first name and the first letter of the second name are chosen for the initials. | |
preferredInitials | string | If you want full control over the initials, use | |
as | React.ElementType | Optional override of the default element used by the component. Any valid tag or Component. If you provided a Component, this component should forward the ref using Note: Not all elements make sense and some elements may cause accessibility issues. Change this value with care. | div |
ref | React.Ref<R = div> | Optional ref. If the component represents an element, this ref will be a reference to the real DOM element of the component. If |
Anatomy
![]()
- Background: A randomly selected fill color for the initial-based variant.
- Initials: The first letters of a user’s first and last names in a darker gradient of fill color.
- Stroke: The outer circle for the initial-based variant.
- Image: A user-uploaded image of themselves.
Usage Guidance
When to Use
- Use Avatars to provide a user with a stronger identity or when an access point into their profile provides reasonable benefit.
Behaviors
Pressed States
Pressed states pertain to Avatars in standalone instances only. Avatars that are part of a larger selection item do not have individual pressed behaviors.
![]()
Disabled States
Disabled states apply only for non-standalone Avatars, which are a sub-component in a larger composite component such as an Avatar in a list item.
![]()
Loading States
The Avatar should not default to a generic user icon when loading. The Avatar has a skeleton that accommodates different background colors when loading.
![]()
Examples
Avatars vary on the basis of version, sizing, background, and default color.
Version
Avatars default to their initial-based version unless a user manually uploads a profile photo. The lettering inside the Avatar is based on the two letter English initials of the Western equivalent of a user name.
![]()
Sizing
Avatars should feel appropriately sized based on their importance and nearby content. They vary on a scale from XXS to XXL to accommodate an array of different possible use cases:
- XXS: 24 x 24. Please note that it is recommended to use a larger size than XXS for all uses outside of pills.
![]()
- XS: 32 x 32
- S: 40 x 40
- M: 48 x 48
- L: 72 x 72
- XL: 96 x 96
- XXL: 120 x 120
Regardless of Avatar sizing, all tap targets are 48x48 or larger.
![]()
Background
Against darker gradients, white strokes are used to increase contrast. The initial-based variant stroke becomes white and a white stroke is added around the image-based variant.
![]()
Color
Initial-based avatars are randomly assigned a gender neutral and contrast friendly color on a per-user basis.
![]()
API Guidelines
Methods
Class name: Avatar Module name: UIComponentsPlugin
public init(
featureData: FeatureMetricsData,
context: SemanticContext = .default,
imageType: ImageType,
avatarSize: AvatarSize,
avatarColor: AvatarColor = .chiliMango,
isOnDarkBackground: Bool = false,
isEnabled: Bool = true,
isLoading: Bool = false,
onClick: @escaping (() -> Void) = {}
)Parameters
| Name | Description | Default values |
|---|---|---|
| featureData | the feature name/context and the screen ID in which the component appears. | |
| context | the SemanticContext. | SemanticContext.default |
| imageType | Type of image for the Avatar to use. | |
| avatarSize | Size of the Avatar UI Component. | |
| avatarColor | Background color of the Avatar UI Component. | chiliMango |
| isOnDarkBackground | Bool indicating if the avatar is being used on a dark background. | false |
| isEnabled | Bool indicating if the avatar is enabled. | true |
| isLoading | Bool indicating if the avatar should show the loading state. | false |
| onClick | Closure that represents an action associated with the avatar tap. |
Accessibility Guidelines
Coming soon…
Anatomy
![]()
- Background: A randomly selected fill color for the initial-based variant.
- Initials: The first letters of a user’s first and last names in a darker gradient of fill color.
- Stroke: The outer circle for the initial-based variant.
- Image: A user-uploaded image of themselves.
Usage Guidance
When to Use
- Use Avatars to provide a user with a stronger identity or when an access point into their profile provides reasonable benefit.
Behaviors
Pressed States
Pressed states pertain to Avatars in standalone instances only. Avatars that are part of a larger selection item do not have individual pressed behaviors.
![]()
Disabled States
Disabled states apply only for non-standalone Avatars, which are a sub-component in a larger composite component such as an Avatar in a list item.
![]()
Loading States
The Avatar should not default to a generic user icon when loading. The Avatar has a skeleton that accommodates different background colors when loading.
![]()
Examples
Avatars vary on the basis of version, sizing, background, and default color.
Version
Avatars default to their initial-based version unless a user manually uploads a profile photo. The lettering inside the Avatar is based on the two letter English initials of the Western equivalent of a user name.
![]()
Sizing
Avatars should feel appropriately sized based on their importance and nearby content. They vary on a scale from XXS to XXL to accommodate an array of different possible use cases:
- XXS: 24 x 24. Please note that it is recommended to use a larger size than XXS for all uses outside of pills.
![]()
- XS: 32 x 32
- S: 40 x 40
- M: 48 x 48
- L: 72 x 72
- XL: 96 x 96
- XXL: 120 x 120
Regardless of Avatar sizing, all tap targets are 48x48 or larger.
![]()
Background
Against darker gradients, white strokes are used to increase contrast. The initial-based variant stroke becomes white and a white stroke is added around the image-based variant.
![]()
Color
Initial-based avatars are randomly assigned a gender neutral and contrast friendly color on a per-user basis.
![]()
API Guidelines
Methods
fun AvatarUiComponent(
modifier: Modifier = Modifier,
avatarSizeConfig: AvatarSizeConfig = AvatarSizeConfig.S,
avatarColorConfig: AvatarColorConfig = AvatarColorConfig.ChiliMango,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
onColorBackground: Boolean = false,
enabled: Boolean = true,
isLoading: Boolean = false,
initials: String,
imageResourceId: Int? = null,
bitmap: Bitmap? = null,
role: Role? = null,
onClick: (() -> Unit)? = null,
)Parameters
| Name | Description | Default values |
|---|---|---|
| avatarSizeConfig | Enum that determines the size of the Avatar. Options: XXS, XS, S, M, L, XL, XXL. | S |
| avatarColorConfig | Enum that determines the color of the Avatar. Options: ChiliMango, FruitPunch, IslandPunch, Plum, Toothpaste, Jewel, Watermelon, GreenApple, Kiwi | ChiliMango |
| interactionSource | The [MutableInteractionSource] representing the stream of Interactions for this [AvatarUiComponent]. You can create and pass in your own remembered [MutableInteractionSource] if you want to observe Interactions and customize the appearance / behavior of this [AvatarUiComponent] in different Interactions. | remember { MutableInteractionSource() } |
| onColorBackground | Boolean to let the component know whether it is being rendered on a dark or light background. The Avatar will change the border color to account for the dark/light background. | false |
| enabled | Controls the enabled state of the button. When false, this button will not be clickable | true |
| isLoading | Boolean that puts the Avatar into a loading state using the skeleton loader ui component when true | false |
| initials | String to be displayed in the Avatar if no image is provided. Will only take the first two characters in the string or the entire string if its less than two characters | true |
| imageResourceId | resource ID of image to be shown in the avatar | null |
| bitmap | alternative option to provide image to be shown in the avatar | null |
| role | Role to be passed in for a11y readout | null |
| onClick | Lambda to be called when the Avatar is clicked | null |
Accessibility Guidelines
Coming soon…
Can't Find What You Need?
Check out our FAQ section which may help you find the information you're looking for. For further information, contact the #ask-canvas-design or #ask-canvas-kitchannels on Slack.