nook
Browse the docs

Components

Avatar

Built on Base UI

A user image with a text fallback while loading or when it fails.

See the prompt
FSNKAB

Installation

npx nook-ui@latest add avatar

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Avatar" component to this project, exactly as Nook ships it.

A user image with a text fallback while loading or when it fails.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add avatar`. It writes `components/ui/avatar.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/avatar.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";

export default function AvatarDefault() {
  return (
    <div className="flex items-center gap-4">
      <Avatar>
        <AvatarImage src="/broken-image.png" alt="" />
        <AvatarFallback>FS</AvatarFallback>
      </Avatar>
      <Avatar className="size-12">
        <AvatarFallback>NK</AvatarFallback>
      </Avatar>
      <Avatar className="size-8 text-xs">
        <AvatarFallback>AB</AvatarFallback>
      </Avatar>
    </div>
  );
}
```

API
- `Avatar`: The circle container.
  - `status` (`"online" | "away" | "busy" | "offline"`): Shows presence in a corner mark. It is also written for screen readers.
- `AvatarImage`: The image.
  - `src` (`string`): Image URL.
  - `alt` (`string`): Alternative text.
- `AvatarFallback`: Initials or an icon shown when there is no image.
  - `delay` (`number`): Milliseconds to wait before showing, to avoid a flash.
- `AvatarGroup`: Overlaps several avatars and rings each one so they read apart.
  - `...props` (`React.HTMLAttributes<HTMLDivElement>`): Everything the native element accepts, such as `id`, `aria-*` and event handlers.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Always set `alt` on the image. Use `alt=""` when the person's name is shown next to the avatar.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";

export default function AvatarDefault() {
  return (
    <div className="flex items-center gap-4">
      <Avatar>
        <AvatarImage src="/broken-image.png" alt="" />
        <AvatarFallback>FS</AvatarFallback>
      </Avatar>
      <Avatar className="size-12">
        <AvatarFallback>NK</AvatarFallback>
      </Avatar>
      <Avatar className="size-8 text-xs">
        <AvatarFallback>AB</AvatarFallback>
      </Avatar>
    </div>
  );
}

Examples

Presence and groups

MCOnlineonline
ARAwayaway
LFBusybusy
SOOfflineoffline
MCARLF+3

Sizes

MOMOMOMOMO

Avatar groups

ATDRSOLFJP
ATDRSO+4

With name and presence

  • MOOnline
    Maya OkaforProduct designer
  • TRAway
    Tomás RiveraEngineering lead
  • LFOffline
    Lena FischerOn leave until 4 May

Fallbacks

PNKMBusy

Props

Avatar

The circle container.

PropTypeDefaultDescription
status"online" | "away" | "busy" | "offline"–Shows presence in a corner mark. It is also written for screen readers.

AvatarImage

The image.

PropTypeDefaultDescription
srcstring–Image URL.
altstring–Alternative text.

AvatarFallback

Initials or an icon shown when there is no image.

PropTypeDefaultDescription
delaynumber–Milliseconds to wait before showing, to avoid a flash.

AvatarGroup

Overlaps several avatars and rings each one so they read apart.

PropTypeDefaultDescription
...propsReact.HTMLAttributes<HTMLDivElement>–Everything the native element accepts, such as `id`, `aria-*` and event handlers.

Accessibility

Always set `alt` on the image. Use `alt=""` when the person's name is shown next to the avatar.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.