Skip to main contentSkip to docs navigation

Chassis

Display a user profile as a picture or short text with avatars, in seven sizes, as buttons or links, with status badges and overlapping stacks.

@layer components
Context tokens

Introduction

Avatars represent a user or an entity as a picture or as short text, such as initials. An avatar is an inline element of equal width and height, round by default, that can carry a status badge and join other avatars in an overlapping stack.

Basic structure

Add the .avatar class to an element that holds short text, which is rendered in uppercase, or an <img> with the .avatar-image class, which fills the avatar and takes its radius.

CX Profile picture
HTML
<span class="avatar">CX</span>
<span class="avatar">
  <img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture" />
</span>

Sizes

Use the .2xs, .xs, .sm, .md, .lg, .xl, .2xl classes to set the size of the avatar, or set the --cx-avatar-size custom property for a custom size. The font size of a text avatar scales with it.

CX CX CX CX CX CX CX CX CX
HTML
<span class="avatar 2xs">CX</span>
<span class="avatar xs">CX</span>
<span class="avatar sm">CX</span>
<span class="avatar md">CX</span>
<span class="avatar lg">CX</span>
<span class="avatar xl">CX</span>
<span class="avatar 2xl">CX</span>
<span class="vr mx-md"></span>
<span class="avatar" style="--cx-avatar-size: 1.75rem;">CX</span>
<span class="avatar" style="--cx-avatar-size: 4.25rem;">CX</span>
Profile picture Profile picture Profile picture Profile picture Profile picture Profile picture Profile picture Profile picture Profile picture
HTML
<span class="avatar 2xs"><img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/></span>
<span class="avatar xs"><img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/></span>
<span class="avatar sm"><img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/></span>
<span class="avatar md"><img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/></span>
<span class="avatar lg"><img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/></span>
<span class="avatar xl"><img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/></span>
<span class="avatar 2xl"><img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/></span>
<span class="vr mx-md"></span>
<span class="avatar" style="--cx-avatar-size: 1.75rem;"><img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/></span>
<span class="avatar" style="--cx-avatar-size: 4.25rem;"><img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/></span>

Buttons

Add the .avatar class to a <button> element for an avatar that triggers an action. The avatar shows the focus ring on keyboard focus and is dimmed when disabled.

HTML
<button class="avatar" type="button">CX</button>
<button class="avatar" type="button">
  <img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/>
</button>

Add the .avatar class to an <a> element for an avatar that navigates, to a profile page for example.

HTML
<a class="avatar" href="#">CX</a>
<a class="avatar" href="#">
  <img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/>
</a>

Colors

Add a context color class, such as .primary, to color a text avatar from that context. The .smooth class next to it switches to the subdued colors of the context.

HTML
<button class="avatar default" type="button">CX</button>
<button class="avatar alternate" type="button">CX</button>
<button class="avatar primary" type="button">CX</button>
<button class="avatar secondary" type="button">CX</button>
<button class="avatar neutral" type="button">CX</button>
<button class="avatar danger" type="button">CX</button>
<button class="avatar success" type="button">CX</button>
<button class="avatar warning" type="button">CX</button>
<button class="avatar info" type="button">CX</button>
<button class="avatar black" type="button">CX</button>
<button class="avatar white" type="button">CX</button>
HTML
<button class="avatar smooth default" type="button">CX</button>
<button class="avatar smooth alternate" type="button">CX</button>
<button class="avatar smooth primary" type="button">CX</button>
<button class="avatar smooth secondary" type="button">CX</button>
<button class="avatar smooth neutral" type="button">CX</button>
<button class="avatar smooth danger" type="button">CX</button>
<button class="avatar smooth success" type="button">CX</button>
<button class="avatar smooth warning" type="button">CX</button>
<button class="avatar smooth info" type="button">CX</button>
<button class="avatar smooth black" type="button">CX</button>
<button class="avatar smooth white" type="button">CX</button>

Badges

A .badge placed inside an avatar becomes a status indicator at its bottom end corner, with no position utilities needed. Give the badge visually hidden text, since its color alone does not convey the status to assistive technology.

HTML
<button class="avatar" type="button">
  <img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/>
  <span class="badge success circle"><span class="visually-hidden">Online</span></span>
</button>
<button class="avatar" type="button">
  <img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/>
  <span class="badge danger circle"><span class="visually-hidden">Offline</span></span>
</button>
<button class="avatar" type="button">
  <img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/>
  <span class="badge warning circle"><span class="visually-hidden">Away</span></span>
</button>
<button class="avatar" type="button">
  <img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/>
  <span class="badge neutral circle"><span class="visually-hidden">Busy</span></span>
</button>

The badge is a quarter of the avatar size, so it scales with every avatar size.

HTML
<button class="avatar 2xs" type="button">
  <img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/>
  <span class="badge success circle"><span class="visually-hidden">Online</span></span>
</button>
<button class="avatar xs" type="button">
  <img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/>
  <span class="badge success circle"><span class="visually-hidden">Online</span></span>
</button>
<button class="avatar sm" type="button">
  <img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/>
  <span class="badge success circle"><span class="visually-hidden">Online</span></span>
</button>
<button class="avatar md" type="button">
  <img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/>
  <span class="badge success circle"><span class="visually-hidden">Online</span></span>
</button>
<button class="avatar lg" type="button">
  <img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/>
  <span class="badge success circle"><span class="visually-hidden">Online</span></span>
</button>
<button class="avatar xl" type="button">
  <img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/>
  <span class="badge success circle"><span class="visually-hidden">Online</span></span>
</button>
<button class="avatar 2xl" type="button">
  <img class="avatar-image" src="https://i.pravatar.cc/256" alt="Profile picture"/>
  <span class="badge success circle"><span class="visually-hidden">Online</span></span>
</button>

Stacks

Wrap avatars in an .avatar-stack element to group them with an overlap. The --cx-avatar-stack-spacing custom property sets the overlap as a fraction of the avatar size, and an interactive avatar of a stack is raised and enlarged on hover and keyboard focus.

HTML
<div class="avatar-stack">
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=39" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=35" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=52" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=32" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=37" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=10" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=30" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=25" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=26" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">+5</button>
</div>

A size class on the stack sets the size of all its avatars.

HTML
<div class="avatar-stack 2xs">
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=49" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=55" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=1" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=9" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">+5</button>
</div>
<div class="avatar-stack xs">
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=24" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=36" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=25" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=1" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">+5</button>
</div>
<div class="avatar-stack sm">
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=48" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=51" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=57" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=32" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">+5</button>
</div>
<div class="avatar-stack md">
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=53" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=16" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=23" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=0" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">+5</button>
</div>
<div class="avatar-stack lg">
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=34" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=61" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=12" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=24" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">+5</button>
</div>
<div class="avatar-stack xl">
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=33" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=52" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=20" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=1" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">+5</button>
</div>
<div class="avatar-stack 2xl">
  <button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=53" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=19" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=16" alt="Profile picture"/>
  </button>
<button class="avatar" type="button">
    <img class="avatar-image" src="https://i.pravatar.cc/256?img=36" alt="Profile picture"/>
  </button>
  <button class="avatar" type="button">+5</button>
</div>

CSS

The Avatar component can be customized at both runtime (via custom properties) and compile time (via Sass variables).

Sass variables

The Avatar component uses Sass variables in scss/config/_defaults.scss to define its defaults; they are also exposed as CSS custom properties using the --cx- prefix for runtime override — $variable-name becomes --cx-variable-name. See the component anatomy page.

$avatar-size: 2.5rem;
$avatar-fg-color: var(--fg-solid);
$avatar-bg-color: var(--bg-solid);
$avatar-border-color: var(--border-subtle);
$avatar-border-width: var(--border-width-md);
$avatar-border-radius: var(--border-radius-full);
$avatar-font-family: var(--font-family-ui);
$avatar-font-weight: var(--font-weight-ui-strong);
$avatar-font-scale: .4;
$avatar-badge-border-width: var(--border-width-xl);
$avatar-badge-border-color: var(--bg-main);
$avatar-stack-spacing: -.25;
$avatar-focus-ring-offset: 0px;
$avatar-transition: transform .15s ease-in-out;