---
title: Empty for Astro
description: "Astro empty-state parts for lists, searches, and unfinished setup."
seo:
    title: Empty for Astro | Shadcn & Tailwind CSS
related:
    - /components/skeleton
    - /components/alert
sidebar:
    label: "Empty"
---

```astro
---
import QuestionMarkIcon from "@lucide/astro/icons/circle-question-mark"

import { Button } from "@/components/ui/button"
import {
  Empty,
  EmptyContent,
  EmptyDescription,
  EmptyHeader,
  EmptyMedia,
  EmptyTitle,
} from "@/components/ui/empty"
---

<Empty>
  <EmptyHeader>
    <EmptyMedia variant="icon">
      <QuestionMarkIcon />
    </EmptyMedia>
    <EmptyTitle>404 - Page Not Found</EmptyTitle>
    <EmptyDescription>
      No page matches this address. Return to the index to choose another page.
    </EmptyDescription>
  </EmptyHeader>
  <EmptyContent>
    <Button size="sm"> Go home </Button>
  </EmptyContent>
</Empty>
```

## Installation

### Command

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

### Manual

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

No extra packages are required.

#### src/components/ui/empty/empty-content.astro

```astro
---
/**
 * Actions under an empty state, such as a button, input, or link.
 */
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div
  data-slot="empty-content"
  class={cn("flex w-full min-w-0 max-w-sm flex-col items-center gap-4 text-sm text-balance", className)}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/empty/empty-description.astro

```astro
---
/**
 * Supporting text for an empty state.
 * A description that follows the title keeps a small gap above it.
 */
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div
  data-slot="empty-description"
  class={cn("text-sm text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary [[data-slot=empty-title]+&]:mt-1", className)}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/empty/empty-header.astro

```astro
---
/**
 * Groups the media, title, and description of an empty state.
 * The group stays narrow and centered.
 */
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div
  data-slot="empty-header"
  class={cn("flex max-w-sm flex-col items-center text-center", className)}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/empty/empty-media.astro

```astro
---
/**
 * Media for an empty state: an icon, an image, or another component.
 *
 * `variant="icon"` draws two offset cards behind the icon.
 * Those cards are decorative. The slot stays on the front card.
 * A `class` on this component also reaches each card, so a size or color
 * change stays on the whole stack.
 *
 * @see https://coss.com/ui/docs/components/empty
 */
import type { HTMLAttributes } from "astro/types"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "cn"

const emptyMediaVariants = cva("flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0", {
  defaultVariants: {
    variant: "default",
  },
  variants: {
    variant: {
      default: "bg-transparent",
      icon: "relative flex size-9 shrink-0 items-center justify-center rounded-md border bg-card text-foreground shadow-sm/5 not-dark:bg-clip-padding before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-md)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)] [&_svg:not([class*='size-'])]:size-4.5",
    },
  },
})

type Props = HTMLAttributes<"div"> & VariantProps<typeof emptyMediaVariants>

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

/** Shared face for the front card and the two offset cards. */
const cardClass = cn(emptyMediaVariants({ variant }), className)
---

<div
  data-slot="empty-media"
  data-variant={variant}
  class={cn("relative mb-6", className)}
  {...props}
>
  {variant === "icon" && (
    <>
      <div
        aria-hidden="true"
        data-slot="empty-media-decoration"
        class={cn(
          cardClass,
          "pointer-events-none absolute bottom-px origin-bottom-left -translate-x-0.5 -rotate-10 scale-84 shadow-none",
        )}
      />
      <div
        aria-hidden="true"
        data-slot="empty-media-decoration"
        class={cn(
          cardClass,
          "pointer-events-none absolute bottom-px origin-bottom-right translate-x-0.5 rotate-10 scale-84 shadow-none",
        )}
      />
    </>
  )}
  <div data-slot="empty-media-content" data-variant={variant} class={cardClass}>
    <slot />
  </div>
</div>
```

#### src/components/ui/empty/empty-title.astro

```astro
---
/**
 * Title of an empty state.
 * `font-heading` follows the sans face until a theme sets another heading font.
 */
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div data-slot="empty-title" class={cn("font-heading text-xl font-semibold", className)} {...props}>
  <slot />
</div>
```

#### src/components/ui/empty/empty.astro

```astro
---
/**
 * Root container for an empty state.
 * Place `EmptyHeader` and `EmptyContent` inside it.
 *
 * @see https://coss.com/ui/docs/components/empty
 */
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div data-slot="empty" class={cn("flex min-w-0 flex-1 flex-col items-center justify-center gap-6 px-6 py-12 text-center text-balance md:py-20", className)} {...props}>
  <slot />
</div>
```

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

```ts
/** Empty state parts. Styles follow https://coss.com/ui/docs/components/empty */
export { default as Empty } from "./empty.astro"
export { default as EmptyContent } from "./empty-content.astro"
export { default as EmptyDescription } from "./empty-description.astro"
export { default as EmptyMedia } from "./empty-media.astro"
export { default as EmptyTitle } from "./empty-title.astro"
export { default as EmptyHeader } from "./empty-header.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 {
    Empty,
    EmptyContent,
    EmptyDescription,
    EmptyHeader,
    EmptyMedia,
    EmptyTitle,
} from "@/components/ui/empty"
```

```astro
---
import Inbox from "@lucide/astro/icons/inbox"

import { Button } from "@/components/ui/button"
import {
  Empty,
  EmptyContent,
  EmptyDescription,
  EmptyHeader,
  EmptyMedia,
  EmptyTitle,
} from "@/components/ui/empty"
---

<Empty>
  <EmptyHeader>
    <EmptyMedia variant="icon">
      <Inbox />
    </EmptyMedia>
    <EmptyTitle>No data</EmptyTitle>
    <EmptyDescription>No data found.</EmptyDescription>
  </EmptyHeader>
  <EmptyContent>
    <Button>Add data</Button>
  </EmptyContent>
</Empty>
```

## Composition

Arrange the parts as shown for an `Empty` state:

```text
Empty
├── EmptyHeader
│   ├── EmptyMedia
│   ├── EmptyTitle
│   └── EmptyDescription
└── EmptyContent
```

## Examples

### Default

```astro
---
import {
  Empty,
  EmptyHeader,
  EmptyMedia,
  EmptyTitle,
  EmptyDescription,
  EmptyContent,
} from "@/components/ui/empty"
import { Button } from "@/components/ui/button"
import { Image } from "astro:assets"
import { agentAvatars } from "@/lib/agent-avatars"

const supportAgent = agentAvatars[0]
---

<Empty>
  <EmptyHeader>
    <EmptyMedia>
      <Image
        src={supportAgent}
        alt="Support Agent"
        width={72}
        height={72}
        position="center"
        fit="cover"
        class="rounded-full grayscale-100"
      />
    </EmptyMedia>
    <EmptyTitle>Need help?</EmptyTitle>
    <EmptyDescription>
      Send the page address and a short description of the issue so the team can
      check it.
    </EmptyDescription>
  </EmptyHeader>
  <EmptyContent>
    <div class="flex gap-2">
      <Button variant="outline">No Thanks</Button>
      <Button>Contact Us</Button>
    </div>
  </EmptyContent>
</Empty>
```

## Notes

- Use `EmptyHeader` when you want the media, title, and description grouped as
  one block.
- `EmptyMedia variant="icon"` is a good default for simple status states.
- Add `EmptyContent` only when the empty state needs an action such as retry,
  clear filters, or go back.

## API Reference

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

## When to use Empty

Use Empty where content will appear after an action or data change. Explain why the area is empty and give one useful next step. Add media only when it helps explain the state.

## Keyboard and behavior

Empty is static markup. Actions inside it use normal links or buttons. For search results updated by a script, announce the result count through an appropriate live region in your application.

## Theme and layout

Spacing and muted text make the message distinct without a heavy surface. Check the action row at narrow widths and avoid fixed heights that create large blank regions.
