Live demo
Demo source
Use an avatar to represent a person or account in lists, comments, headers and menus. Show the person's name beside it; the avatar helps recognition but does not replace the name.
Content types
An avatar shows one of three things, in this order:
- Image from
src, withaltdescribing who it shows. - Initials from
initials, trimmed to two characters. The application decides which letters to use. - Icon: a default user icon, or your own icon in the
iconslot, for guests or shared accounts.
A broken image does not fall back to initials automatically; clear src when
your application knows an image is unavailable.
Size and colour
size offers xs, sm, md (the default), lg and xl. color picks one
of ten background colours: amber, orange, yellow, red, turquoise,
crimson, green, petrol, lime and gray. The older values 1 to 10
still work. Colours have no meaning of their own, so keep a person's colour
stable, for example by deriving it from their name.
Guidelines
- Use two-letter initials, such as the first letters of the first and last names.
- Use one size within a list.
- Don't rely on colour or the image alone to identify someone.
Accessibility
Set alt to the person's name when the avatar identifies them without adjacent
text; the component uses it on the host and image. If the same name is already
visible and the avatar adds no information, hide the decorative avatar with
aria-hidden="true".
The design page describes keyboard access, but an avatar is not an interactive control by itself. Put a clickable profile avatar inside a labelled link or button, and let that control provide keyboard behaviour and focus styling.