Avatar
Visual representation of a user or entity via image, initials, or fallback icon.
Renders an accessible image with alt text derived from name; falls back to initials or a labelled fallback when no image is available. Status dots are decorative (aria-hidden) — pair them with a textual label when status conveys meaning.
import { Avatar } from '@arshad-shah/cynosure-react';
export default function Example() {
return <Avatar name="Jane Doe" />;
}
With image
Section titled “With image”Provide an src to render an <img>. When the image fails or is still loading, Avatar gracefully falls back to initials derived from name.
import { Avatar } from '@arshad-shah/cynosure-react';
export default function Example() {
return <Avatar name="Ada Lovelace" src="https://i.pravatar.cc/120?img=47" />;
}
Avatar ships six sizes — xs, sm, md (default), lg, xl, and 2xl.
import { Avatar } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '0.75rem', alignItems: 'center' }}>
<Avatar name="Jane Doe" size="xs" />
<Avatar name="Jane Doe" size="sm" />
<Avatar name="Jane Doe" size="md" />
<Avatar name="Jane Doe" size="lg" />
<Avatar name="Jane Doe" size="xl" />
<Avatar name="Jane Doe" size="2xl" />
</div>
);
}
Shapes
Section titled “Shapes”Pick between circle (default), rounded, and square shapes.
import { Avatar } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '0.75rem', alignItems: 'center' }}>
<Avatar name="Jane Doe" shape="circle" />
<Avatar name="Jane Doe" shape="rounded" />
<Avatar name="Jane Doe" shape="square" />
</div>
);
}
Initials and color
Section titled “Initials and color”When src is missing, Avatar shows the initials derived from name. A deterministic colour from the built-in palette is auto-selected per name; override with colorScheme (red, amber, green, blue, violet, pink, teal, orange).
import { Avatar } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '0.75rem', alignItems: 'center' }}>
<Avatar name="Ada Lovelace" />
<Avatar name="Grace Hopper" />
<Avatar name="Linus Torvalds" />
<Avatar name="Margaret Hamilton" />
<Avatar name="Donald Knuth" colorScheme="violet" />
<Avatar initials="?" colorScheme="teal" />
</div>
);
}
Status indicator
Section titled “Status indicator”Pass status (online, offline, away, busy) to render a presence dot. Use statusPosition to anchor it to bottom-right (default) or top-right.
import { Avatar } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '0.75rem', alignItems: 'center' }}>
<Avatar name="Jane Doe" status="online" />
<Avatar name="John Smith" status="away" />
<Avatar name="Sam Chen" status="busy" />
<Avatar name="Ada Lovelace" status="offline" />
<Avatar name="Grace Hopper" status="online" statusPosition="top-right" />
</div>
);
}
Set ring to add a tokenised ring around the avatar — useful for stacked groups or highlighting the current user.
import { Avatar } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '0.75rem', alignItems: 'center' }}>
<Avatar name="Jane Doe" ring />
<Avatar name="John Smith" ring size="lg" />
<Avatar name="Ada Lovelace" ring src="https://i.pravatar.cc/120?img=12" size="xl" />
</div>
);
}
Accessibility
Section titled “Accessibility”- Provide a
nameso initials andalttext stay meaningful when the image is missing. - When the avatar is purely decorative, leave
nameempty and addaria-hidden="true"on the wrapping element. - Status dots render with
aria-hidden="true"— pair them with an off-screen label or adjacent text when status conveys meaning. - The fallback waits 400ms before swapping in initials so users on fast networks see the image first.
- Initials are rendered inside a fallback element which exposes an
aria-labelwhen only a name (no derived initials) is available.
Recipes
Section titled “Recipes”- Combine
srcwithnameso initials are ready as a graceful fallback. - Use
ringon the current user’s avatar to disambiguate them in a roster. - Override
colorSchemeonly when brand colour matters — the deterministic palette keeps an avatar’s colour stable across renders. - Compose multiple avatars inside
<AvatarGroup>to represent collaborators with optional overflow.