---
title: Avatar for Astro
description: "Astro profile images and text fallbacks in a shared size system."
seo:
    title: Avatar for Astro | Shadcn & Tailwind CSS
related:
    - /components/item
    - /components/badge
sidebar:
    label: "Avatar"
---

```astro
---
import {
  Avatar,
  AvatarFallback,
  AvatarGroup,
  AvatarImage,
} from "@/components/ui/avatar"
import { agentAvatars } from "@/lib/agent-avatars"
---

<div class="flex flex-row flex-wrap items-center gap-12">
  <Avatar>
    <AvatarImage src={agentAvatars[0]} alt="Example teammate" />
    <AvatarFallback>SV</AvatarFallback>
  </Avatar>
  <Avatar size="lg">
    <AvatarImage src={agentAvatars[0]} alt="Example teammate" />
    <AvatarFallback>SV</AvatarFallback>
  </Avatar>
  <Avatar size="lg">
    <AvatarFallback>MR</AvatarFallback>
  </Avatar>
  <AvatarGroup class="*:grayscale">
    <Avatar>
      <AvatarImage src={agentAvatars[0]} alt="Example teammate" />
      <AvatarFallback>SV</AvatarFallback>
    </Avatar>
    <Avatar>
      <AvatarImage src={agentAvatars[1]} alt="Example teammate" />
      <AvatarFallback>SV</AvatarFallback>
    </Avatar>
    <Avatar>
      <AvatarImage src={agentAvatars[2]} alt="Example teammate" />
      <AvatarFallback>SV</AvatarFallback>
    </Avatar>
  </AvatarGroup>
</div>
```

## Installation

### Command

```sh
bunx --bun shadcn@latest add @gnostic/avatar
```

### Manual

Complete the [Installation guide](/docs/installation) first. Then copy the component files below.

No extra packages are required.

#### src/components/ui/avatar/avatar-badge.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"span">

const { class: className, ...props } = Astro.props
---

<span
  data-slot="avatar-badge"
  class={cn("bg-primary text-primary-foreground ring-background absolute right-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full bg-blend-color ring-2 select-none group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2 group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2", className)}
  {...props}
>
  <slot />
</span>
```

#### src/components/ui/avatar/avatar-fallback.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

const { class: className, ...props } = Astro.props
---

<div
  data-slot="avatar-fallback"
  class={cn("absolute inset-0 flex size-full items-center justify-center rounded-full bg-muted group-data-[size=lg]/avatar:text-sm group-data-[size=sm]/avatar:text-xs", className)}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/avatar/avatar-group-count.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

const { class: className, ...props } = Astro.props
---

<div
  data-slot="avatar-group-count"
  class={cn("bg-muted text-muted-foreground ring-background relative flex size-8 shrink-0 items-center justify-center rounded-full text-sm ring-2 group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3", className)}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/avatar/avatar-group.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

const { class: className, ...props } = Astro.props
---

<div
  data-slot="avatar-group"
  class={cn(
    "*:data-[slot=avatar]:ring-background group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2",
    className,
  )}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/avatar/avatar-image.astro

```astro
---
import { Image } from "astro:assets"
import type { ComponentProps } from "astro/types"

import { cn } from "cn"

type Props = Partial<ComponentProps<typeof Image>>

const {
  class: className,
  alt = "",
  width = 44,
  height = 44,
  sizes = "44px",
  widths = [44, 88, 176],
  ...props
} = Astro.props
---

{props.src && (
  <Image
    data-slot="avatar-image"
    class={cn("absolute inset-0 z-10 aspect-square size-full rounded-full object-cover", className)}
    alt={alt}
    width={width}
    height={height}
    sizes={sizes}
    widths={widths}
    {...(props as any)}
  />
)}
```

#### src/components/ui/avatar/avatar.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div"> & {
  size?: "default" | "sm" | "lg"
}

const { class: className, size = "default", ...props } = Astro.props
---

<div
  data-slot="avatar"
  data-size={size}
  class={cn("relative isolate inline-flex size-8 shrink-0 select-none items-center justify-center overflow-hidden rounded-full bg-background align-middle font-medium text-xs data-[size=lg]:size-10 data-[size=sm]:size-6 group/avatar", className)}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/avatar/index.ts

```ts
export { default as Avatar } from "./avatar.astro"
export { default as AvatarBadge } from "./avatar-badge.astro"
export { default as AvatarFallback } from "./avatar-fallback.astro"
export { default as AvatarGroup } from "./avatar-group.astro"
export { default as AvatarGroupCount } from "./avatar-group-count.astro"
export { default as AvatarImage } from "./avatar-image.astro"
```

Component classes use the preset configured during project setup. Select the same preset in the docs before copying Manual source. To change installed component classes, edit or reinstall their source. See [Theming](/docs/theming) for details.


## Usage

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

```astro
<Avatar>
  <AvatarImage src="/avatar.jpg" alt="Team member" />
  <AvatarFallback>TM</AvatarFallback>
</Avatar>
```

## Composition

Arrange the parts as shown for an `Avatar`:

```text
Avatar
├── AvatarImage
├── AvatarFallback
└── AvatarBadge
```

Arrange the parts as shown for an `AvatarGroup`:

```text
AvatarGroup
├── Avatar
│   ├── AvatarImage
│   ├── AvatarFallback
│   └── AvatarBadge
├── Avatar
│   ├── AvatarImage
│   ├── AvatarFallback
│   └── AvatarBadge
└── AvatarGroupCount
```

## Examples

### Fallback

Use `AvatarFallback` when an image is unavailable or intentionally omitted.

```astro
---
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
---

<Avatar size="lg">
  <AvatarFallback>MR</AvatarFallback>
</Avatar>
```

### Group

Use `AvatarGroup` when you need overlapping participant or collaborator lists.

```astro
---
import {
  Avatar,
  AvatarFallback,
  AvatarGroup,
  AvatarGroupCount,
  AvatarImage,
} from "@/components/ui/avatar"
import { agentAvatars } from "@/lib/agent-avatars"
---

<AvatarGroup>
  <Avatar>
    <AvatarImage src={agentAvatars[0]} alt="Example teammate" />
    <AvatarFallback>SV</AvatarFallback>
  </Avatar>
  <Avatar>
    <AvatarImage src={agentAvatars[1]} alt="Example teammate" />
    <AvatarFallback>TM</AvatarFallback>
  </Avatar>
  <AvatarGroupCount>+3</AvatarGroupCount>
</AvatarGroup>
```

## Notes

- Always include `AvatarFallback` so initials or placeholder content remain
  visible when the image fails to load.
- Use size variants on `Avatar` instead of custom width and height classes when
  possible.

## API Reference

Read the [installed source](/r/avatar.json) for the complete prop types.

## When to use Avatar

Use Avatar beside a person or team name. Put AvatarImage and AvatarFallback inside the same root. Use initials or a short mark for the fallback, and choose one size for a row of related people.

## Keyboard and behavior

Supply meaningful image alternative text if the image conveys identity that is absent from nearby text. Use empty alt text when the adjacent name already supplies it. This Astro version does not include Base UI image loading state; a broken image URL does not automatically switch to the fallback.

## Theme and layout

The root clips content to its rounded shape and the fallback uses muted colors. Check long initials and transparent logos in both modes. Resolve an absent image in your data before rendering when you need a reliable fallback.
