1. Docs
  2. Components
  3. Avatar

Avatar

An image element with a fallback for representing the user.

Installation

npx shadcn@latest add @kanpeki/avatar

Usage

Single import

import { Avatar } from "~/components/ui/avatar";
import { Icons } from "~/components/icons";
<Avatar.Root>
  <Avatar.Image src="https://github.com/fellipeutaka.png" alt="@fellipeutaka" />
  <Avatar.Fallback>FU</Avatar.Fallback>
  <Avatar.Placeholder>
    <Icons.User className="size-6" />
  </Avatar.Placeholder>
</Avatar.Root>

Multiple imports

import {
  AvatarRoot,
  AvatarFallback,
  AvatarImage,
  AvatarPlaceholder,
} from "~/components/ui/avatar";
import { Icons } from "~/components/icons";
<AvatarRoot>
  <AvatarImage src="https://github.com/fellipeutaka.png" alt="@fellipeutaka" />
  <AvatarFallback>FU</AvatarFallback>
  <AvatarPlaceholder>
    <Icons.User className="size-6" />
  </AvatarPlaceholder>
</AvatarRoot>

Examples

Default

Group

API Reference

Root

Contains all the parts of an avatar.

Image

The image to render. By default it will only render when it has loaded.

Fallback

An element that renders when the image hasn't loaded. This means whilst it's loading, or if there was an error.

Placeholder

An element that renders when the image is loading.