Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / Feedback and display

Avatar

A person, team or thing shown as a picture, falling back to initials and then to an icon. AvatarGroup overlaps several and sums up the rest as "+3". An avatar only shows who it is; to make one pressable, put it inside a Button or Link.

Tones and one off colour

When to useLink to "When to use"

  • Who did or owns something: the author of a comment, the people assigned to a task, the account in a menu.
  • A thing with an identity: a team, a workspace or a project, with icon or shape="square".
  • Several people in little space: AvatarGroup with max.

Use something else when:

  • the picture is content, not an identity: Image
  • it is a status or a category with no person behind it: Badge
  • it is only an icon: Icon
  • the person is still loading: Skeleton with shape="circle"

UsageLink to "Usage"

tsx
Copy
import { Avatar, AvatarGroup } from "@arshad-shah/cynosure";
import { folder } from "@arshad-shah/cynosure/icons";

<Avatar name="Ada Lovelace" />
<Avatar name="Ada Lovelace" src={ada.photo} status="online" />
<Avatar name="Design files" icon={folder} shape="square" />

<AvatarGroup label="Reviewers" max={3}>
  {reviewers.map((person) => (
    <Avatar key={person.id} name={person.name} src={person.photo} />
  ))}
</AvatarGroup>

Picture, initials, iconLink to "Picture, initials, icon"

name is required: it is what assistive technology reads and where the initials come from. The initials are the first letters of the first and last word, upper-cased; one word gives one letter. Whole emoji and non-Latin letters are kept. initials replaces them.

Initials come from the name

With src, the fallback shows while the picture loads and stays if it fails; the broken picture is removed. A new src is tried again.

Picture replaces the fallback

icon is for things that are not people: it shows instead of initials worked out from the name. A name with no letter, number or emoji shows the user icon.

Icon fallback

Sizes and shapesLink to "Sizes and shapes"

size is xs, sm, md (default), lg or xl. sm, md and lg are the control heights, so an avatar lines up with a Button or a field of the same size. shape="square" rounds the corners like a control of that size.

Tone and colourLink to "Tone and colour"

tone colours the fallback; color takes any CSS colour for a one-off. tone="auto" picks one of accent, info, success, warning or danger from the name: the same name always gets the same tone, on every render and on the server. It is decoration that makes a list easier to scan, never the only way to tell people apart: show or speak the name too.

Auto tone follows the name

StatusLink to "Status"

status adds a dot at the bottom end corner and is spoken after the name: "Ada Lovelace, online". Translate the words with labels.

Status is spoken with the name

GroupLink to "Group"

AvatarGroup overlaps its avatars along the reading direction and gives them all its size. With max, the avatars past that number become one "+N" avatar whose accessible name counts and lists them ("3 more: Katherine Johnson, Barbara Liskov, Margaret Hamilton"); change the words with labels.more(count, names). label names the group.

Group summarises the rest

PropsLink to "Props"

Every prop of Avatar
PropWhat it doesTypeDefault
nameRequired
Who or what it is: the accessible name, and where the initials come from. An empty name is not announced.string
initials
Replaces the initials worked out from name (one or two characters).string
src
The picture. The fallback shows while it loads, and stays when it is missing or fails to load.string
icon
The fallback for things that are not people: shown instead of initials worked out from name. Without it, a name with no letters falls back to the user icon.IconData
size
Width and height. Inside an AvatarGroup the group's size is used. Default "md".AvatarSize"md"
shape
Outline: a circle, or a square with rounded corners. Default "circle"."circle" | "square""circle"
tone
Colour of the fallback. "auto" picks a tone from name, the same one every time, so people in a list are easier to tell apart (decoration: the name still has to be shown or spoken). Default "neutral".Tone | "auto""neutral"
color
Any CSS colour for the fallback, for a one-off. Overrides tone.string
status
A dot at the corner, spoken after the name ("Ada Lovelace, online").AvatarStatus
labels
The spoken names of the statuses, to translate them.Partial<AvatarLabels>
decorative
Hides the avatar from assistive technology, for when the name is written beside it.boolean
className
Added to the root element, for layout.string
style
Layout only. Restyle through --cy-avatar-* tokens.CSSProperties

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

AvatarGroupLink to "AvatarGroup"

Every prop of Avatar
PropWhat it doesTypeDefault
nameRequired
Who or what it is: the accessible name, and where the initials come from. An empty name is not announced.string
initials
Replaces the initials worked out from name (one or two characters).string
src
The picture. The fallback shows while it loads, and stays when it is missing or fails to load.string
icon
The fallback for things that are not people: shown instead of initials worked out from name. Without it, a name with no letters falls back to the user icon.IconData
size
Width and height. Inside an AvatarGroup the group's size is used. Default "md".AvatarSize"md"
shape
Outline: a circle, or a square with rounded corners. Default "circle"."circle" | "square""circle"
tone
Colour of the fallback. "auto" picks a tone from name, the same one every time, so people in a list are easier to tell apart (decoration: the name still has to be shown or spoken). Default "neutral".Tone | "auto""neutral"
color
Any CSS colour for the fallback, for a one-off. Overrides tone.string
status
A dot at the corner, spoken after the name ("Ada Lovelace, online").AvatarStatus
labels
The spoken names of the statuses, to translate them.Partial<AvatarLabels>
decorative
Hides the avatar from assistive technology, for when the name is written beside it.boolean
className
Added to the root element, for layout.string
style
Layout only. Restyle through --cy-avatar-* tokens.CSSProperties

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

Avatar has no keyboard or pointer behaviour: it cannot be focused or pressed.

  • Name: the root has role="img" and is named by name. The picture inside has alt="" and the initials are not announced separately, so the name is read once.
  • Status: part of the accessible name, so it never depends on colour. Offline is also drawn hollow.
  • Decorative: when the name is written beside the avatar, decorative hides it from assistive technology (aria-hidden, no role). An avatar with an empty name is hidden the same way.
  • Group: role="group" named by label. The "+N" avatar is an image named by labels.more.
  • Contrast: fallback initials keep 4.5:1 or better in every tone (tested).
  • Right to left: the status dot sits at the left corner and a group overlaps towards the left.
  • Forced colours: an outline keeps the avatar's shape and the status dot draws in the text colour.

TouchLink to "Touch"

Nothing to touch. When an avatar is wrapped in a Button or Link, that component provides the hit area.

ThemingLink to "Theming"

Tokens: --cy-avatar-size-{xs,sm,md,lg,xl}, --cy-avatar-radius, --cy-avatar-font-weight, --cy-avatar-soft-mix, --cy-avatar-status-size, --cy-avatar-ring-color, --cy-avatar-ring-width and --cy-avatar-overlap.

Theming, table 1
TokenWhat it sets
--cy-avatar-size-{xs,sm,md,lg,xl}Width and height at each size
--cy-avatar-radiusCorner radius of the square shape
--cy-avatar-font-weightWeight of the initials
--cy-avatar-soft-mixTint strength of the fallback (percentage of the tone mixed into the surface)
--cy-avatar-status-sizeDiameter of the status dot
--cy-avatar-ring-colorColour of the ring around grouped avatars and the status dot; set it to the surface they sit on
--cy-avatar-ring-widthWidth of that ring
--cy-avatar-overlapHow far each avatar in a group slides over the one before it
ts
Copy
createTheme({ components: { avatar: { radius: "4px", overlap: "6px" } } });

className and style are for layout only.

Badge · Skeleton · Image · Icon

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog