Skip to main content

What are you looking for?

Try searching for…

Components

Avatar stack

Avatar stack stacks a collection of avatar elements

Avatar stack is under development. If you have feedback or suggestions, please report them on Github or in Slack.

Press Enter to start editing
Unable to parse html
const Preview = () => (
  <EXPERIMENTAL_AvatarStack>
    <Avatar aria-label='cat'>
      <img src='/img/component-docs/cats/cat1.webp' alt='' />
    </Avatar>
    <Avatar aria-label='briefcase'>
      <BriefcaseIcon />
    </Avatar>
    <Avatar aria-label='Søren Magnussen'>sm</Avatar>
    <Avatar aria-label='Mark Downright'>md</Avatar>
    <Avatar aria-label='Ola Nordman'>on</Avatar>
  </EXPERIMENTAL_AvatarStack>
);

render(<Preview />)

Usage

To create an avatar stack in plain HTML, use the ds-avatar-stack class on a <span>. Inside this, place elements with the ds-avatar class. Note that if you want to use data-expandable="fixed", the number of avatars must be specified via --dsc-avatar-count: <number> to correctly calculate the fixed width. Use data-suffix to add a text indicator for hidden avatars.

aria-label or aria-description can be used on avatar stack to provide context to screen readers about what the stack represents.

CSS variables and data attributes

Avatar stack uses its own CSS variables to control gap, size and overlap.

CSS Variables
NameValue
--dsc-avatar-stack-sizevar(--ds-size-12)
--dsc-avatar-stack-gap2px
--dsc-avatar-stack-overlap50
--dsc-avatar-countinitial
--dsc-avatar-sizevar(--dsc-avatar-stack-size)
--dsc-avatar-font-sizevar(--_font-size)
Data Attributes
NameValue
data-expandablefixed
data-suffix
data-variantsquare

Examples

Expandable

data-expandable animates overlap to 0 on hover or focus. Use data-expandable="fixed" to expand with overflow without changing the physical width. tabindex="0" should be added, this is automatically added with expandable in React.

Indicating avatars not shown

Avatar stack does not support wrapping across multiple lines. If there are more avatars than can fit in the stack, you can use suffix to indicate this as text to the right of the stack. This automatically scales with the avatar size. You can also use an avatar with +xx as initials or child, but you should override the font size on this avatar with --dsc-avatar-font-size if there is to be room for two-digit or higher numbers.

Sizes

You cannot use data-size to change the size of avatars in an avatar stack. Instead, the size is controlled by setting the --dsc-avatar-stack-size variable.

Gap

Avatar stack uses CSS mask to create the visible space between avatars. This can be adjusted by setting the --dsc-avatar-stack-gap variable.

React

gap
Description

Adjusts gap-mask between avatars in the stack. Must be a valid css length value (px, em, rem, var(--ds-size-1) etc.)

Type
string
Default
2px
avatarSize
Description

Control the size of the avatars. Must be a valid css length value (px, em, rem, var(--ds-size-12) etc.)

Type
string
Default
'var(--ds-size-12)'
overlap
Description

A number which represents the percentage value of how much avatars should overlap.

Type
number
Default
50
suffix
Description

Text to the right of the avatars to show a number representing additional avatars not shown such as '+5'".

Type
string
expandable
Description

Expand on hover to show full avatars. 'fixed': AvatarStack physical width does not change when avatars are expanded.

Type
true | "fixed"
Default
undefined
NameTypeDefaultDescription
gapstring2px

Adjusts gap-mask between avatars in the stack. Must be a valid css length value (px, em, rem, var(--ds-size-1) etc.)

avatarSizestring'var(--ds-size-12)'

Control the size of the avatars. Must be a valid css length value (px, em, rem, var(--ds-size-12) etc.)

overlapnumber50

A number which represents the percentage value of how much avatars should overlap.

suffixstring-

Text to the right of the avatars to show a number representing additional avatars not shown such as '+5'".

expandabletrue | "fixed"undefined

Expand on hover to show full avatars. 'fixed': AvatarStack physical width does not change when avatars are expanded.

Use asChild to make an avatar a link.

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