Avatar
ML
npx shadcn add @klarhimmel/avatarCopy for AIExamples
Image
Sizes
Fallback
DetailsAbout, usage, props and more
A person or team as a photo, or as initials on a colour picked from the name.
When to use
Use for
Next to a name in lists, comments, headers and assignee pickers.
Not for
Logos and product images. Use Media.
Pairs with
Badge, Card, a name in text.
Preview
Photo, photo, a photo that failed to load (initials), and a square for a team.
Import
Import
- Files
- avatar.tsx, in components/klarhimmel/ui/. With it: theme, utils.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | required | Whose face this is. Becomes the accessible name and the initials. |
size | keyof typeof sizes | 'md' | 24, 32, 40 and 56 px. |
square | boolean | - | A rounded square, for teams and organisations. |
src | string | - | A photo. Falls back to initials if it is missing or fails to load. |
srcSet | string | - | A photo. Falls back to initials if it fails to load. |
decorative | boolean | - | Hide it from assistive tech when the name is written next to it. |
className | string | - | Extra classes, merged after the component's own. |
Accessibility
| Key | Does |
|---|---|
Tab | Skips it: an avatar is not interactive |
Screen reader | Reads the name. With decorative set, it reads nothing |
Not interactive. Wrap it in a link or button yourself if it should be.
Accessibility