Components

Avatar

An image element with a fallback for representing the user.

PreviewSource
CNER
CNLRER
+3

Installation

Complete the project setup first. The init command configures TypeScript, Vite, Tailwind CSS v4, and Preact compatibility.

CLI

Run init once using the installation guide, then add this component. The CLI copies the required source files and installs their exact dependencies with Bun.

bunx --bun github:LiasCode/shadcn-preact#main add avatar

Add --dry-run to review the changes. Existing modified files are protected; use --overwrite only when you want to replace them.

Manual installation / degit (optional)

1. Install dependencies

bun add --exact cn@0.4.0 preact@11.0.1 tw-animate-css@1.4.0

2. Copy the component with degit

Run this from your project root. It selects avatar.tsx, its local dependencies, and both licenses directly from the repository, then copies them into src/components/ui.

bunx degit@3.10.0 https://github.com/LiasCode/shadcn-preact#main ./.cache/shadcn-preact/avatar --files LICENSE.md,registry/ui/avatar.tsx,registry/ui/lib/utils.ts,registry/ui/primitives/LICENSE,registry/ui/primitives/avatar/fallback/AvatarFallback.tsx,registry/ui/primitives/avatar/image/AvatarImage.tsx,registry/ui/primitives/avatar/image/useImageLoadingStatus.ts,registry/ui/primitives/avatar/index.parts.ts,registry/ui/primitives/avatar/index.ts,registry/ui/primitives/avatar/root/AvatarRoot.tsx,registry/ui/primitives/avatar/root/AvatarRootContext.ts,registry/ui/primitives/avatar/root/stateAttributesMapping.ts,registry/ui/primitives/internals/empty.ts,registry/ui/primitives/internals/getReactElementRef.ts,registry/ui/primitives/internals/getStateAttributesProps.ts,registry/ui/primitives/internals/mergeObjects.ts,registry/ui/primitives/internals/resolveClassName.ts,registry/ui/primitives/internals/resolveRef.ts,registry/ui/primitives/internals/resolveStyle.ts,registry/ui/primitives/internals/stateAttributesMapping.ts,registry/ui/primitives/internals/types.ts,registry/ui/primitives/internals/useAnimationFrame.ts,registry/ui/primitives/internals/useAnimationsFinished.ts,registry/ui/primitives/internals/useIsoLayoutEffect.ts,registry/ui/primitives/internals/useMergedRefs.ts,registry/ui/primitives/internals/useOnMount.ts,registry/ui/primitives/internals/useOpenChangeComplete.ts,registry/ui/primitives/internals/useRefWithInit.ts,registry/ui/primitives/internals/useRenderElement.ts,registry/ui/primitives/internals/useStableCallback.ts,registry/ui/primitives/internals/useTimeout.ts,registry/ui/primitives/internals/useTransitionStatus.ts,registry/ui/primitives/merge-props/index.ts --force
mkdir -p ./src/components/ui
cp -R ./.cache/shadcn-preact/avatar/registry/ui/. ./src/components/ui/
cp ./.cache/shadcn-preact/avatar/LICENSE.md ./src/components/ui/LICENSE.md

The temporary copy lives in .cache/shadcn-preact/avatar. Existing components stay in place; shared source files are updated from main.

Selected source files (32)

Usage

import { Avatar, AvatarFallback, AvatarImage } from "./components/ui/avatar"
<Avatar>
  <AvatarImage src="https://github.com/shadcn.png" />
  <AvatarFallback>CN</AvatarFallback>
</Avatar>

Examples

Basic

A basic avatar component with an image and a fallback.

BasicSource
CN

Badge

Use the AvatarBadge component to add a badge to the avatar. The badge is positioned at the bottom right of the avatar.

BadgeSource
CN

Badge with Icon

You can also use an icon inside <AvatarBadge>.

Badge with IconSource
PP
Example requirements
bun add --exact lucide-preact@1.55.0

Avatar Group

Use the AvatarGroup component to add a group of avatars.

Avatar GroupSource
CNLRER

Avatar Group Count

Use <AvatarGroupCount> to add a count to the group.

Avatar Group CountSource
CNLRER
+3

Avatar Group with Icon

You can also use an icon inside <AvatarGroupCount>.

Avatar Group with IconSource
CNLRER
Example requirements
bun add --exact lucide-preact@1.55.0

Sizes

Use the size prop to change the size of the avatar.

SizesSource
CNCNCN

Reference

See the official Avatar documentation for composition patterns and API details. This page uses the Preact port and examples from the pinned upstream revision.

Component source