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.

HTML

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-icon-urlurl("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1em' height='1em' fill='none' viewBox='0 0 24 24'%3E%3Cpath fill='currentColor' fill-rule='evenodd' d='M8.25 7.5a3.75 3.75 0 1 1 7.5 0 3.75 3.75 0 0 1-7.5 0M12 2.25a5.25 5.25 0 1 0 0 10.5 5.25 5.25 0 0 0 0-10.5M8.288 17.288A5.25 5.25 0 0 1 17.25 21a.75.75 0 0 0 1.5 0 6.75 6.75 0 0 0-13.5 0 .75.75 0 0 0 1.5 0 5.25 5.25 0 0 1 1.538-3.712' clip-rule='evenodd'/%3E%3C/svg%3E")
--dsc-avatar-backgroundvar(--ds-color-base-default)
--dsc-avatar-colorvar(--ds-color-base-contrast-default)
--dsc-avatar-size2.625em
--dsc-avatar-padding0.45em
--dsc-avatar-font-size1.3em

Example

Variants

The variant prop can be set to square or circle. circle is the default.

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

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

The shape of the avatar.

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.

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)