If you answer yes, we store and analyse information that helps us improve the website. You can change your choice at any time at the bottom of the page. More about what we store and why.

We also store necessary information that cannot be opted out of. This makes the website work and keeps it secure.

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
<span aria-label="Ola Nordmann" class="ds-avatar" role="img"></span>
const Preview = () => <Avatar aria-label='Ola Nordmann' />;

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.

No relevant data attributes found.

CSS Variables
NameValue
--dsc-avatar-backgroundvar(--ds-color-base-default)
--dsc-avatar-colorvar(--ds-color-base-contrast-default)
--dsc-avatar-font-sizecalc(var(--dsc-avatar-size) * .4)
--dsc-avatar-icon-urlurl("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1em' height='1em' fill='none' viewBox='0 0 24 24' focusable='false' role='img'%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/path%3E%3C/svg%3E")
--dsc-avatar-paddingvar(--ds-size-2)
--dsc-avatar-radiusvar(--ds-border-radius-full)
--dsc-avatar-sizevar(--ds-size-12)

Example

With initials

Place text inside avatar to show initials.

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.

Shape and radius

Use --dsc-avatar-radius CSS custom property to adjust the radius of the avatar.

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. @deprecated Please use text content as children instead

Type
string
data-initials
Description

Initials to display inside the avatar. @deprecated Please use text content as children instead

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.

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. @deprecated Please use text content as children instead

data-initialsstring-

Initials to display inside the avatar. @deprecated Please use text content as children instead

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.

Composition

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

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