Atoms · Avatar
Avatar
A small square that shows who someone is. The name is required, because it's both the alt text (the description screen readers read for an image) and the source of the initials. Without one, an avatar is just an image nobody can identify.
- Best for
- Showing who a person is, next to their name, as in a roster row, a comment or an account menu.
- Not for
- Several people in one spot: use AvatarGroup.
This page as Markdown, a plain-text copy for a coding agent (an AI tool that writes code).
Examples
Sizes
Dana IversonDana IversonDana Iverson
Code
tsx
<Avatar name="Dana Iverson" size="sm" /><Avatar name="Dana Iverson" size="md" /><Avatar name="Dana Iverson" size="lg" />With an image
Code
tsx
const DEMO_IMAGE = 'data:image/svg+xml;utf8,' + encodeURIComponent( '<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64">' + '<rect width="64" height="32" fill="#7c9c6b"/>' + // token-discipline: allow, pixels of a sample photo, not interface colour '<rect y="32" width="64" height="32" fill="#3f5a49"/>' + '</svg>' )<Avatar name="Dana Iverson" src={DEMO_IMAGE} size="lg" />Fallback initials
Dana IversonRavi OkonkwoLin
Code
tsx
<Avatar name="Dana Iverson" size="lg" /><Avatar name="Ravi Okonkwo" size="lg" /><Avatar name="Lin" size="lg" />Status: the dot is decoration, and the status word is part of the avatar's name
Ilse Varga, online
Ilse Varga
Ravi Okonkwo, away
Ravi Okonkwo
Mei Tanaka, busy
Mei Tanaka
Sana Idrissi, offline
Sana Idrissi
Code
tsx
const STATUS_TEAM = [ { name: 'Ilse Varga', status: 'online' }, { name: 'Ravi Okonkwo', status: 'away' }, { name: 'Mei Tanaka', status: 'busy' }, { name: 'Sana Idrissi', status: 'offline' },] as const<div className="flex flex-col gap-3"> {STATUS_TEAM.map(member => ( <div key={member.name} className="flex items-center gap-3"> <Avatar name={member.name} status={member.status} size="md" /> <div> <p className="text-sm">{member.name}</p> {/* Shown as text too, so a sighted user never has to decode the colour. Hidden from assistive tech, which already heard it in the avatar's name. */} <p aria-hidden="true" className="text-sm text-[var(--color-text-secondary)] capitalize"> {member.status} </p> </div> </div> ))}</div>A row
Dana Iverson
Dana Iverson
Route Lead
Ravi Okonkwo
Ravi Okonkwo
Comms
Mei Tanaka
Mei Tanaka
Medic
Sana Idrissi
Sana Idrissi
Logistics
Code
tsx
const FIELD_TEAM = [ { name: 'Dana Iverson', role: 'Route Lead' }, { name: 'Ravi Okonkwo', role: 'Comms' }, { name: 'Mei Tanaka', role: 'Medic' }, { name: 'Sana Idrissi', role: 'Logistics' },]<div className="flex flex-col gap-3"> {FIELD_TEAM.map(member => ( <div key={member.name} className="flex items-center gap-3"> <Avatar name={member.name} size="md" /> <div> <p className="text-sm">{member.name}</p> <p className="text-xs text-[var(--color-text-muted)]">{member.role}</p> </div> </div> ))}</div>Anatomy
| Part | What it is |
|---|---|
| Root | A border.hairline-strong edge on the sunken surface, with overflow clipped and a cut bottom-right corner at md and lg. |
| Image | alt is empty on purpose, because the hidden name already does the announcing. |
| Fallback | Initials worked out from the name, aria-hidden, shown when there's no image or it fails to load. aria-hidden is an ARIA attribute (Accessible Rich Internet Applications, the labels that tell screen readers what things are) that hides something from screen readers. |
| Hidden name | sr-only (visible to screen readers only) and always there, so the announcement is the same either way. With a status it reads "Ilse Varga, online". |
| Status dot | Optional. A square in the top-right corner (the bottom-right is the cut), in accent.ok.text, accent.warning.text, accent.hostile.text or text.muted, with a 2px (pixel) surface.base keyline around it. It's aria-hidden because the status is announced in the name. |
Props
- namestring
- Required. The source of the fallback initials and the announced name.
- srcstring
- Optional image. If it can't load, the fallback takes its place without the layout jumping.
- size'sm' | 'md' | 'lg'Default 'md'
- 24 / 36 / 48px.
- status'online' | 'away' | 'busy' | 'offline'
- Whether the person is around. It adds the dot and adds the word to the announced name. Leave it out when you don't know.
- classNamestring
- Merged with the component's classes. When Tailwind utility classes clash, the later one wins.
- refRef<HTMLSpanElement>
- Passed through to the root element.
- ...restOmit<HTMLAttributes<HTMLSpanElement>, 'aria-label' | 'children'>
- Every native span prop except aria-label and children. aria-label is removed from the types rather than quietly overwritten when the page runs. The announced name comes from the sr-only span, and an aria-label on the root would override it. children is removed because the component renders its own image/fallback/sr-only children, so anything passed as children would silently disappear.
Keyboard
You can't reach this component with the keyboard. It has no keyboard behaviour of its own.
Do and don't
Do
- Pass the full name, not the initials. The component works those out itself.
- Let it fall back. The fallback is part of the design, not an error state.
- Use sm inside dense rows and tables.
- Set status only where presence is live and matters (a roster, a chat). A dot that's out of date is worse than no dot.
Don't
- Don't round it. The system has no round corners, and an avatar isn't the place to start.
- Don't add the cut corner to the sm avatar. It's 24px, the same size Kbd leaves out by name. An 8px cut takes a third of that edge, and it looks like a broken square instead of a shaped one.
- Don't build an overlapping stack by hand. AvatarGroup does it, with a '+N' that's real text.
- Don't explain the dot colours only in a legend. The status word is already in the name, so show it as text where sighted users need it too.
- Don't use an avatar as the only label for a person. Put the name next to it in dense UI (user interface).
- Don't pass aria-label. It's removed from the types so nothing can override it, and name already decides the one label that gets announced.