Skip to main content

What are you looking for?

Try searching for…

Components

Avatar

Avatar displays an image, initials, or icon for a person, entity, or profile.

Press Enter to start editing
Unable to parse html
const Preview = () => (
  <Avatar aria-label='Ola Nordmann' variant='circle' />
);

render(<Preview />)

Usage

Avatar uses the class name ds-avatar on a <span> with role="img".Ensure the avatar has an accessible name.

CSS variables and data attributes

Sizes are controlled with data-size and colors with data-color. The component will inherit from the closest parent where these are set.

Data Attributes
NameValue
data-initials
data-variantsquare
CSS Variables
NameValue
--dsc-avatar-backgroundvar(--ds-color-base-default)
--dsc-avatar-colorvar(--ds-color-base-contrast-default)
--dsc-avatar-font-size1.3em
--dsc-avatar-icon-urlurl("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%221em%22%20height%3D%221em%22%20fill%3D%22none%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20fill%3D%22currentColor%22%20fill-rule%3D%22evenodd%22%20d%3D%22M8.25%207.5a3.75%203.75%200%201%201%207.5%200%203.75%203.75%200%200%201-7.5%200M12%202.25a5.25%205.25%200%201%200%200%2010.5%205.25%205.25%200%200%200%200-10.5M8.288%2017.288A5.25%205.25%200%200%201%2017.25%2021a.75.75%200%200%200%201.5%200%206.75%206.75%200%200%200-13.5%200%20.75.75%200%200%200%201.5%200%205.25%205.25%200%200%201%201.538-3.712%22%20clip-rule%3D%22evenodd%22%2F%3E%3C%2Fsvg%3E")
--dsc-avatar-padding0.45em
--dsc-avatar-radiusvar(--ds-border-radius-full)
--dsc-avatar-size2.625em

Example

Variants

Use data-variant to determine the shape of the avatar. You can choose between circle (default) or square.

With image or icon

Avatar displays a user icon by default, but this can be overridden in CSS using the --dsc-avatar-icon-url variable.

If you add an image or icon as content inside the avatar, make sure to set aria-hidden="true" to avoid duplicate information. You must add an aria-label to the avatar yourself to explain who or what the avatar represents.

React

Avatar

aria-label
Type
string
data-tooltip
Type
string
aria-hidden
Type
Booleanish
variant
Description

The shape of the avatar. @deprecated Please use `style={{ '--dsc-avatar-radius': VALUE }}` instead

Type
"circle" | "square"
Default
'circle'
initials
Description

Initials to display inside the avatar.

Type
string
asChild
Description

Change the default rendered element for the one passed as a child, merging their props and behavior.

Type
boolean
Default
false
children
Description

Image, icon or initials to display inside the avatar. Gets `aria-hidden="true"`

Type
ReactNode
NameTypeDefaultDescription
aria-labelstring-

-

data-tooltipstring-

-

aria-hiddenBooleanish-

-

variant"circle" | "square"'circle'

The shape of the avatar. @deprecated Please use `style={{ '--dsc-avatar-radius': VALUE }}` instead

initialsstring-

Initials to display inside the avatar.

asChildbooleanfalse

Change the default rendered element for the one passed as a child, merging their props and behavior.

childrenReactNode-

Image, icon or initials to display inside the avatar. Gets `aria-hidden="true"`

Composition

The component should be able to be composed into other components. Here is an example of using avatar inside a dropdown component.

Non-text content

If you add anything other than text as a child inside <Avatar> (like an image or icon), it will automatically receive aria-hidden="true" to avoid duplicate information.

Edit this page on github.com (opens in a new tab)