Skip to content

Empty

Fills a view that has no content yet, and tells people what to do next.

No purchase orders yet
Orders raised by purchasing appear here. Create the first one to start tracking deliveries.

Installation

pnpm dlx shadcn@latest add @silkware/empty

To copy the component by hand, install its dependencies:

pnpm add class-variance-authority cn

Then copy the source into components/ui/empty.tsx:

components/ui/empty.tsx
import { cva, type VariantProps } from "class-variance-authority"import { cn } from "cn"
function Empty({ className, ...props }: React.ComponentProps<"div">) {  return (    <div      data-slot="empty"      className={cn(        "flex w-full min-w-0 flex-1 flex-col items-center justify-center gap-4 rounded-lg border-dashed p-12 text-center text-balance",        className      )}      {...props}    />  )}
function EmptyHeader({ className, ...props }: React.ComponentProps<"div">) {  return (    <div      data-slot="empty-header"      className={cn("flex max-w-sm flex-col items-center gap-2", className)}      {...props}    />  )}
const emptyMediaVariants = cva(  "mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0",  {    variants: {      variant: {        default: "bg-transparent",        icon: "flex size-10 shrink-0 items-center justify-center rounded-lg bg-muted text-foreground [&_svg:not([class*='size-'])]:size-6",      },    },    defaultVariants: {      variant: "default",    },  })
function EmptyMedia({  className,  variant = "default",  ...props}: React.ComponentProps<"div"> & VariantProps<typeof emptyMediaVariants>) {  return (    <div      data-slot="empty-icon"      data-variant={variant}      className={cn(emptyMediaVariants({ variant, className }))}      {...props}    />  )}
function EmptyTitle({ className, ...props }: React.ComponentProps<"div">) {  return (    <div      data-slot="empty-title"      className={cn(        "font-heading text-lg font-medium tracking-tight",        className      )}      {...props}    />  )}
function EmptyDescription({ className, ...props }: React.ComponentProps<"p">) {  return (    <div      data-slot="empty-description"      className={cn(        "text-sm/relaxed text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary",        className      )}      {...props}    />  )}
function EmptyContent({ className, ...props }: React.ComponentProps<"div">) {  return (    <div      data-slot="empty-content"      className={cn(        "flex w-full max-w-sm min-w-0 flex-col items-center gap-4 text-sm text-balance",        className      )}      {...props}    />  )}
export {  Empty,  EmptyHeader,  EmptyTitle,  EmptyDescription,  EmptyContent,  EmptyMedia,}

Usage

import {  Empty,  EmptyContent,  EmptyDescription,  EmptyHeader,  EmptyMedia,  EmptyTitle,} from "@/components/ui/empty"
<Empty>  <EmptyHeader>    <EmptyMedia variant="icon">      <PackageOpenIcon />    </EmptyMedia>    <EmptyTitle>No purchase orders yet</EmptyTitle>    <EmptyDescription>Create the first one to start tracking deliveries.</EmptyDescription>  </EmptyHeader>  <EmptyContent>    <Button>Create purchase order</Button>  </EmptyContent></Empty>

Empty has no border width, so on its own it floats. Its border style is dashed, so border through className draws a dashed frame and border border-solid a solid one. It fills the width and the free height of its parent, with 48px of padding.

Examples

Outline

Add border border-solid to frame the message inside a page that has other content around it.

No deliveries this week
Nothing is due at Brescia until Monday.

Dashed

A dashed border suggests a place where something can be added, such as an empty group.

No suppliers in this group
Add a supplier to compare delivery times across sites.

With avatars

EmptyMedia without a variant holds any content. Use it for an avatar group when the missing thing is people.

GR
LB
MC
Nobody is assigned to this line
Assign Giulia, Luca or Marco so the next shift has an owner.

No results

A search or a filter that finds nothing is a different case from a view that has never had content. Say what was searched and how to widen it.

No orders match “Lombardia”
Check the spelling, or search by supplier name or order number.

Accessibility

KeyAction
TabMoves focus to the action inside the empty state, if there is one.

React Aria provides nothing here: the empty state is built from plain elements.

You provide:

  • Text that says what is missing, because an icon alone says nothing to a screen reader. The icon in EmptyMedia is decoration.
  • A real Button or link for the next step.
  • A heading level on EmptyTitle, which is a div, when the empty state is the main content of the page: add role="heading" and an aria-level.
  • An announcement, with role="status", when the state appears after a search or a filter, so people hear that nothing matched.

Guidelines

When to use

  • When a list, table or page has no content yet, and a person can create some.
  • When a search or filter returns nothing.
  • When a section is cleared, such as an inbox with every item handled.

When not to use

  • While data loads. Use a Skeleton or a Spinner.
  • When loading fails. Use an Alert with a way to retry.
  • For a one-line note inside a table. Use the table's own empty state, as shown in Table.
  • For a message about permissions or status. Use an Alert.

Content

  • The title says what is missing, in a few words: "No purchase orders yet".
  • The description says why, or what to do, in one or two short sentences.
  • Offer one action, in the active form: "Create purchase order". For a no-results state, offer to clear the search.
  • Keep the tone calm. No jokes, no exclamation marks.

Next step

No quality checks today
Marco schedules checks by line. Schedule one to see results here.
Do

Say what is missing and give the next step.

Nothing here
Don’t

Don’t leave a dead end. "Nothing here" explains neither why nor what to do.

API reference

Empty

Renders a centred flex div. It accepts every div prop.

EmptyHeader

Renders a div that stacks media, title and description in a column no wider than 384px. It accepts every div prop.

EmptyMedia

Renders the visual of the empty state.

PropTypeDefaultDescription
variant?"default" | "icon""default"Bare content, or an icon on a 40px muted tile.

EmptyTitle

Renders a div in the heading font. It accepts every div prop.

EmptyDescription

Renders a div in muted text. Links inside it are underlined. It accepts every div prop.

EmptyContent

Renders a div for the actions, no wider than 384px. It accepts every div prop.