--- title: Avatar description: Avatars identify people or entities with a photo, initials, or generic fallback. Size variants keep them proportional in lists, bylines, and toolbars. category: Data display --- import { meta as AvatarMeta, Default } from '@/content/stories/avatar'; import Canvas from '@/components/component-docs/canvas'; import Demo from '@/components/component-docs/demo'; export const config = { dependencies: { components: [Canvas, Demo], scripts: [ '../../components/component-docs/demo.script.tsx', '../../components/component-docs/canvas.script.tsx', '../../components/component-docs/controls.script.tsx', ], }, }; # Avatar
Avatars identify people or entities with a photo, initials, or generic fallback. Size variants keep them proportional in lists, bylines, and toolbars.
## Try itLimit fallback to one or two characters derived from the person's name. Avoid arbitrary symbols that do not identify the subject.
## Pick size for contextUse `sm` in dense tables and comment threads, `md` in bylines and menus, and `lg` in profile headers.
## Theming Avatar chrome maps to **semantic surface roles**, never Tailwind palette steps. Override `--rui-avatar-*` on `.rui-avatar`. Size classes set `--rui-avatar-size`. | Part | Default | Override | | --- | --- | --- | | Size | `--space-10` (`md`); `sm` `--space-8`; `lg` `--space-12` | `--rui-avatar-size` | | Fill / radius | `--surface-container`, `--radius-pill` | `--rui-avatar-surface`, `--rui-avatar-radius` | | Fallback text | `on-surface` | theme | ```css .rui-avatar { --rui-avatar-size: 2.25rem; } ``` ## Accessibility - Always provide `alt` text when `src` is set so the image is described to screen readers. - When showing only initials, ensure surrounding text names the person; the avatar itself may be decorative. - Do not use avatar color as the sole indicator of user role or status. ## API `RuiAvatar` is a presentational JSX view, no custom element. Pass `src` for an image, or `fallback` / `alt` for initials. ### Props | Prop | Type | Default | Description | | --- | --- | --- | --- | | `src` | `string` | | Image URL. When omitted, initials from `alt` / `fallback` are shown. | | `alt` | `string` | `''` | Accessible name for the image; also derives initials. | | `fallback` | `string` | | Explicit fallback initials / text when there is no image. | | `size` | `sm` · `md` · `lg` | `md` | Avatar size. | ### CSS classes Public BEM classes (documented via `@cssclass`): | Class | Description | | --- | --- | | `.rui-avatar` · `--sm` · `--md` · `--lg` | Root + size variants. | | `.rui-avatar__image` | `