Avatar
A person or thing as an image with an initials fallback.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- 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
| Prop | Type | Default | Description |
|---|---|---|---|
src | string | – | Image URL. If it fails or is missing, the initials show. |
name required | string | – | 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
| Class | Stylesheet |
|---|---|
.avatar | 19-avatar.css |
.avatar-group | 19-avatar.css |
.avatar-lg | 19-avatar.css |
.avatar-line | 19-avatar.css |
.avatar-sm | 19-avatar.css |
.stat | 19-avatar.css |
.stat-note | 19-avatar.css |
.stat-value | 19-avatar.css |
.tag | 19-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.