Skip to content
Thrum

Empty state

What a list, a table or a page shows when there is nothing in it yet: a picture, a title, one sentence and the action that fills it. Use the small size inside a card or a table and the medium one for a page. For a page that failed or does not exist, use the result state.

Install

npx shadcn@latest add https://thrumui.dev/r/empty-state.json

Adds components/ui/empty-state.tsx. Nothing else in your project changes.

import { EmptyState } from "@/components/ui/empty-state";

Props

PropTypeDefaultDescription
EmptyState: size"sm" | "md"Default "md"sm fits inside a card or a table: a 48 pixel picture and 14 pixel title. md fills a page or a panel: a 72 pixel picture and a 16 pixel title.
EmptyState: borderedbooleanDefault falseA dashed edge around it, for an area that something can be added to or dropped on.
EmptyState: headingLevel2 | 3 | 4 | 5 | 6Default 3The heading level of the title, so it fits the outline of the page around it.
EmptyState: ...propsComponentProps<"div">–Every other div attribute is passed through. className is merged last.
EmptyStateMediaComponentProps<"div">–The picture, hidden from screen readers. With no children it draws an empty tray in the border and muted text colours; pass an icon or an image to replace it.
EmptyStateTitleComponentProps<"h3">–What is empty, in a few words. Rendered as the heading level the empty state sets.
EmptyStateDescriptionComponentProps<"p">–Why it is empty and what to do, in the muted colour, at most 384 pixels wide.
EmptyStateActionsComponentProps<"div">–The primary action first, then a secondary one. They wrap and stay centred.

Motion and sound

Motion

  • The empty state does not move.

Sound

Silent. This component makes no sound.

Accessibility

  • The title is a real heading at the level set by headingLevel, so the empty state takes its place in the page outline.
  • The picture is decoration and hidden from screen readers. The title and description carry the message.
  • It is not a live region. When a filter empties a list, announce the result count where the filter is.
  • Title and description wrap, and long words break, so nothing is cut off at 160 pixels wide.
KeysAction
TabMove to the actions, primary first.

Source

components/ui/empty-state.tsx
"use client";

import { createContext, useContext, type ComponentProps } from "react";

import { cn } from "@/lib/utils";

export type EmptyStateSize = "sm" | "md";
export type HeadingLevel = 2 | 3 | 4 | 5 | 6;

export type EmptyStateProps = ComponentProps<"div"> & {
  /** `sm` fits inside a card or a table, `md` fills a page or a panel. */
  size?: EmptyStateSize;
  /** A dashed edge around it, for an area that something can be added to or dropped on. */
  bordered?: boolean;
  /** The heading level of `EmptyStateTitle`, so it fits the outline of the page. */
  headingLevel?: HeadingLevel;
};

const Context = createContext<{ size: EmptyStateSize; level: HeadingLevel }>({ size: "md", level: 3 });

/**
 * What a list, a table or a page shows when it has nothing in it yet: a picture, a title, a sentence and what to do next.
 * Build it from `EmptyStateMedia`, `EmptyStateTitle`, `EmptyStateDescription` and `EmptyStateActions`.
 */
export function EmptyState({ size = "md", bordered = false, headingLevel = 3, className, ...props }: EmptyStateProps) {
  return (
    <Context value={{ size, level: headingLevel }}>
      <div
        data-slot="empty-state"
        data-size={size}
        data-surface={bordered ? "panel" : undefined}
        className={cn(
          "flex w-full min-w-0 flex-col items-center text-center",
          size === "sm" ? "gap-2 px-4 py-6" : "gap-3 px-6 py-10",
          bordered && "rounded-lg border border-foreground/15 bg-card text-card-foreground outline-1 -outline-offset-6 outline-dashed outline-foreground/35",
          className,
        )}
        {...props}
      />
    </Context>
  );
}

/** The picture. Without children it draws an empty tray in the theme's line colours; pass an icon or an image instead. */
export function EmptyStateMedia({ className, children, ...props }: ComponentProps<"div">) {
  const { size } = useContext(Context);
  return (
    <div
      data-slot="empty-state-media"
      aria-hidden="true"
      className={cn("mb-1 grid place-items-center text-muted-foreground", size === "sm" ? "[&>svg]:h-12" : "[&>svg]:h-18", className)}
      {...props}
    >
      {children ?? <EmptyTray />}
    </div>
  );
}

/** The default picture: two sheets over an open tray, drawn in the border and muted text colours. */
function EmptyTray() {
  return (
    <svg viewBox="0 0 120 90" className="w-auto" fill="none" strokeWidth={1.5} strokeLinejoin="round">
      <rect x={34} y={8} width={52} height={46} className="fill-card stroke-foreground/40 [rx:min(var(--radius),4px)]" />
      <rect x={26} y={18} width={68} height={44} className="fill-card stroke-muted-foreground [rx:min(var(--radius),4px)]" />
      <path d="M36 30H70M36 38H84M36 46H62" className="stroke-foreground/40" strokeLinecap="round" />
      <path d="M10 56H38L44 68H76L82 56H110V82H10Z" className="fill-background stroke-muted-foreground" />
    </svg>
  );
}

/** What is empty, in a few words: "No invoices yet". A heading at the level the empty state sets. */
export function EmptyStateTitle({ className, ...props }: ComponentProps<"h3">) {
  const { size, level } = useContext(Context);
  const Heading = `h${level}` as "h3";
  return <Heading data-slot="empty-state-title" className={cn("max-w-full font-semibold break-words", size === "sm" ? "text-sm leading-5" : "text-base leading-6", className)} {...props} />;
}

/** Why it is empty and what to do about it. Keep it to one or two sentences. */
export function EmptyStateDescription({ className, ...props }: ComponentProps<"p">) {
  const { size } = useContext(Context);
  return <p data-slot="empty-state-description" className={cn("max-w-sm break-words text-muted-foreground", size === "sm" ? "text-xs leading-4" : "text-sm leading-5", className)} {...props} />;
}

/** The primary action first, then a secondary one. They wrap and stay centred. */
export function EmptyStateActions({ className, ...props }: ComponentProps<"div">) {
  const { size } = useContext(Context);
  return <div data-slot="empty-state-actions" className={cn("flex flex-wrap items-center justify-center gap-2", size === "sm" ? "mt-1" : "mt-2", className)} {...props} />;
}

Files and dependencies

Adds
components/ui/empty-state.tsx
Packages
None
Brings along
Nothing

Changelog

  1. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor