Playground

Avatar

A person or thing as an image with an initials fallback.

  • Built on radix-ui/Avatar
  • name is required: it is the image alt text and the fallback's accessible name.
  • The fallback shows while the image loads or if it fails.
  • Styles in one file: 19-avatar.css

Import

import '@monoline/css';
import {Avatar} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add avatar

It needs radix-ui; install it if your project does not have it:

npm install radix-ui

Usage

import {Avatar} from '@monoline/react';

<div style={{display: 'flex', gap: 'var(--s3)', alignItems: 'center'}}>
  <Avatar name="Ada Lovelace" />
  <Avatar name="Grace Hopper" variant="line" />
  <Avatar name="Alan Turing" size="lg" />
</div>

Examples

Fallback initials

Props

AvatarProps

PropTypeDefaultDescription
srcstring–Image URL. If it fails or is missing, the initials show.
name requiredstring–The person's name. Used as the image alt text and to make initials; required so it always has a name.
size"sm" | "md" | "lg"'md'`md` (default), `sm` for dense rows or `lg`.
variant"line" | "solid"'solid'`solid` (default) fills the circle; `line` draws only an outline.

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

This component sets no state attributes.

CSS classes

ClassStylesheet
.avatar19-avatar.css
.avatar-group19-avatar.css
.avatar-lg19-avatar.css
.avatar-line19-avatar.css
.avatar-sm19-avatar.css
.stat19-avatar.css
.stat-note19-avatar.css
.stat-value19-avatar.css
.tag19-avatar.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.avatar {
  border-color: var(--accent);
}

Try the props

Change a prop and the component above updates; the code below is what you would write. To edit the code itself, use the Playground.

AL
example.tsx
<Avatar name="Ada Lovelace" />

Accessibility

  • name is required: it is the image alt text and the fallback's accessible name.
  • The fallback shows while the image loads or if it fails.