Avatar
Circular visual representation of a user or entity. Accepts an image, icon
or text and automatically picks the first one available in the order
imgSrc > icon > label.
It is built on top of Flex and inherits the layout
props, so it can be positioned in grids/flexbox without extra wrappers.
import { Avatar } from '@apollion-dsi/core/elements/avatar';
import { trash, user } from '@apollion-dsi/core/icons';
const Example = () => <Avatar label="G" />;When to use
| ✅ Use when… | 🚫 Avoid when… |
|---|---|
|
|
Variations
The Avatar component can be used in different ways, through the
imgSrc, icon or label properties.
<Flex mb="xl" gap="large" flexDirection="row" wrap="wrap">
<Avatar size="large" imgSrc="https://example.com/photo.jpg" />
<Avatar size="large" icon={trash} />
<Avatar size="large" label="G" />
</Flex>Precedence between sources
If more than one source is provided, the image takes precedence over the icon,
which takes precedence over the label. Useful for flows where the photo may
still be loading and you want a graceful fallback:
<Avatar imgSrc={user.photoUrl} icon={user} label={user.initials} />Interactive Demo
imgSrc
loading
label
loading
icon
loading
Properties
Prop | Type | Default | Description |
|---|---|---|---|
alignContent | "center" | "start" | "end" | "between" | "around" | "evenly" | "stretch" | — | Packing of wrapped lines / grid tracks on the block axis. |
alt | string | — | Accessible name — the image's `alt` (with `imgSrc`) or the container's
`aria-label` (with initials). Omit for a decorative avatar.
@example ```tsx
<Avatar imgSrc={photoUrl} alt="Fernando Barros" />
<Avatar label="FB" alt="Fernando Barros" />
``` |
containment | string | — | Containment marker for the `cq` channel: emits
`container-type` (+ `container-name` when the string form carries one,
e.g. `'inline-size card'`). Apply on the immediate wrapper of the
adapting component — NEVER on page-level shells. |
cq | Partial<Record<ContainerSizeTypes, Partial<Omit<Partial<{ area: string; padding: string | number; margin: string | number; isHidden: boolean; truncate: boolean; pageShell: boolean; ... 14 more ...; transform: string; }>, "containment"> & Partial<...> & SizeFactoryProps & Partial<...>>>> | — | Container-relative **layout** styles per `theme.containerSizes` key. |
enableBreakpoint | "xs" | "xl" | "sm" | "md" | "lg" | — | Forces a breakpoint's prop set to apply regardless of viewport (stories/previews). |
icon | IconData | — | Name of the icon (from the set supported by `Icon`) displayed when `imgSrc`
is not provided. Takes precedence over `label`.
@see {@link IconProps.name } for the list of available icons. |
ignoreResponsive | boolean | — | Fully disables the responsive factory (tests / fixed snapshots). |
imgSrc | string | — | URL of the image to display. Takes precedence over `icon` and `label`.
@example ```tsx
<Avatar imgSrc="https://i.pravatar.cc/120" />
``` |
justifyItems | "center" | "start" | "end" | "stretch" | — | Grid containers: inline alignment of every item in its cell. |
label | string | — | Text displayed when neither `imgSrc` nor `icon` is provided. Commonly
used with the user's initials; rendered in uppercase.
@example ```tsx
<Avatar label="FB" />
``` |
legibility | "on-photo" | — | Reading-shadow preset for text over a photographic background
(`on-photo`). Replaces the inline `style={{ textShadow }}` in the
consumer (brasil_2030 radar, gap A3). Token emission is deferred until a
2nd consumer asks for the raw var (see backlog). |
pageShell | boolean | — | Centers the element and caps the width at `theme.layout.pageMaxWidth`.
The page shell of a classic centered layout. |
placeItems | "center" | "start" | "end" | "stretch" | — | Grid containers: `place-items` shorthand (block + inline). |
readable | number | boolean | — | Makes the `color` legible against the page surface: `true` = WCAG AA
(4.5), a number sets a custom floor. Ignored with `contrast`.
See the Layout Props concept page for the full semantics. |
size | "small" | "medium" | "large" | "giant" | "extraLarge" | 'medium' | Size of the avatar. Controls width, height, and the `label` font size. |
transform | string | — | CSS `transform` value (e.g. `translate(-50%, -33px)`). Never leaks
to the DOM as an attribute. |
viewportMedias | Partial<Record<keyof BreakPoint<any>, Partial<Omit<Partial<{ area: string; padding: string | number; margin: string | number; isHidden: boolean; truncate: boolean; pageShell: boolean; container: boolean; ... 13 more ...; transform: string; }>, "containment"> & Partial<...> & SizeFactoryProps & Partial<...>>>> | unde... | — | Viewport-driven **layout** styles per `theme.breakpoints` key. |
Besides the props above, every component accepts the layout props (spacing, color, flex/grid, sizing, border) — not repeated here.
Accessibility
The accessible-name pattern (A14, WCAG image-alt / aria-prohibited-attr):
- Photo avatar — pass
altwith the person's name: it is forwarded to the inner<img>. Omit it for decorative avatars (name already adjacent in text): the image then emitsalt="", which passes audits silently. - Initials avatar — the container exposes
role="img"witharia-label={alt ?? label}automatically; passaltfor a proper name instead of the raw initials. - The
labelprop is a sizing/content input only — it never reaches the DOM as an attribute.
<Avatar imgSrc={photoUrl} alt="Fernando Barros" />
<Avatar label="FB" alt="Fernando Barros" />
<Avatar imgSrc={decorativeUrl} /> {/* alt="" — decorative */}See also
- Storybook story: Components / Avatar
- Base container:
Flex