# EmptyState (/docs/empty-state)





`EmptyState` is what a list shows when it has no rows to draw: an icon in a [`ThemeIcon`](/docs/theme-icon), a title, a muted description and the actions, centred at a minimum height. [`DataTable`](/docs/data-table) draws its empty and error views with it, so a card grid, a timeline or a grouped list that comes up empty (or fails to load) looks the same as a table that does.

```tsx
import { EmptyState } from "@42-central/ui-react/empty-state";
import { FolderPlus } from "lucide-react";

<EmptyState
  icon={<FolderPlus />}
  title="No projects yet"
  description="Projects you create or join show up here."
>
  <Button size="sm">New project</Button>
</EmptyState>;
```

## Basic [#basic]

Only `title` is required. `icon` and `description` each appear when given, and children (the actions) go in a row under the text.

<Preview align="block" code="`<EmptyState icon={<Inbox />} title=&#x22;Your inbox is empty&#x22; />`">
  <EmptyState className="text-sm" icon="<Inbox className={iconStroke} />" title="Your inbox is empty" />
</Preview>

## Description and actions [#description-and-actions]

The description is muted, so the title stays the headline. The children are the actions: they sit below the text and wrap on a narrow container.

<Preview align="block" code="&#x22;<EmptyState\n  icon={<SearchX />}\n  title=\&#x22;No students match your filters\&#x22;\n  description=\&#x22;Try a broader search, or clear the filters.\&#x22;\n>\n  <Button variant=\&#x22;light\&#x22; color=\&#x22;neutral\&#x22; size=\&#x22;sm\&#x22;>Clear filters</Button>\n  <Button size=\&#x22;sm\&#x22; startSlot={<Plus />}>Invite a student</Button>\n</EmptyState>&#x22;">
  <EmptyState className="text-sm" icon="<SearchX className={iconStroke} />" title="No students match your filters" description="Try a broader search, or clear the filters.">
    <Button variant="light" color="neutral" size="sm">
      Clear filters
    </Button>

    <Button size="sm" startSlot="<Plus />">
      Invite a student
    </Button>
  </EmptyState>
</Preview>

## Error [#error]

A list that failed to load must not read like a list with nothing in it. Give it `color="red"`, which tints the icon and the title (the description stays muted), and `role="alert"` so a screen reader announces it. The role is left to you because only you know whether the block appeared in response to something.

<Preview align="block" code="&#x22;<EmptyState\n  color=\&#x22;red\&#x22;\n  role=\&#x22;alert\&#x22;\n  icon={<ServerCrash />}\n  title=\&#x22;Couldn't load the projects\&#x22;\n  description=\&#x22;The server didn't answer. Check your connection and try again.\&#x22;\n>\n  <Button variant=\&#x22;light\&#x22; color=\&#x22;neutral\&#x22; size=\&#x22;sm\&#x22; startSlot={<RefreshCw />} onClick={refetch}>\n    Retry\n  </Button>\n</EmptyState>&#x22;">
  <EmptyState className="text-sm" color="red" role="alert" icon="<ServerCrash className={iconStroke} />" title="Couldn't load the projects" description="The server didn't answer. Check your connection and try again.">
    <Button variant="light" color="neutral" size="sm" startSlot="<RefreshCw />">
      Retry
    </Button>
  </EmptyState>
</Preview>

## Colors [#colors]

`color` takes any palette color. Without one, the icon is the muted `default` tile and the title the primary text color. With one, the icon is that color's `light` tile and the title takes the color's text shade.

<Preview align="block" code="&#x22;<EmptyState color=\&#x22;brand\&#x22; icon={<FolderPlus />} title=\&#x22;Start your first project\&#x22; />\n<EmptyState color=\&#x22;orange\&#x22; icon={<Inbox />} title=\&#x22;Submissions are paused\&#x22; />&#x22;">
  <div className="grid w-full gap-4 sm:grid-cols-2">
    <EmptyState className="text-sm" color="brand" icon="<FolderPlus className={iconStroke} />" title="Start your first project" />

    <EmptyState className="text-sm" color="orange" icon="<Inbox className={iconStroke} />" title="Submissions are paused" />
  </div>
</Preview>

## In a list that isn't a table [#in-a-list-that-isnt-a-table]

The block fills whatever replaces the rows. Here a card grid with no cards shows it inside the grid's frame.

<Preview align="block" code="&#x22;{projects.length === 0 ? (\n  <Card>\n    <EmptyState\n      icon={<FolderPlus />}\n      title=\&#x22;No projects yet\&#x22;\n      description=\&#x22;Projects you create or join show up here.\&#x22;\n    >\n      <Button size=\&#x22;sm\&#x22; startSlot={<Plus />}>New project</Button>\n    </EmptyState>\n  </Card>\n) : (\n  <div className=\&#x22;grid grid-cols-3 gap-4\&#x22;>{projects.map(…)}</div>\n)}&#x22;">
  <Card className="w-full">
    <EmptyState className="text-sm" icon="<FolderPlus className={iconStroke} />" title="No projects yet" description="Projects you create or join show up here.">
      <Button size="sm" startSlot="<Plus />">
        New project
      </Button>
    </EmptyState>
  </Card>
</Preview>

## Font size [#font-size]

`EmptyState` sets no font size: it uses the size of wherever it sits. A table's density therefore carries into its placeholder. In body text, set one with `className` (the demos on this page use `text-sm`).

## Composition [#composition]

For a layout the props don't cover, compose the parts: `EmptyState.Root`, `.Icon`, `.Title`, `.Description` and `.Actions`. The root is a column with a gap between its children, so wrap the title and description in one element to keep them together, as the ready-made form does. A composed `.Title` follows the root's `color` without being told. Pass the same `color` to `.Icon`.

<Preview align="block" code="&#x22;<EmptyState.Root color=\&#x22;orange\&#x22;>\n  <EmptyState.Icon color=\&#x22;orange\&#x22; size=\&#x22;lg\&#x22; radius=\&#x22;full\&#x22;>\n    <Inbox />\n  </EmptyState.Icon>\n  <div>\n    <EmptyState.Title className=\&#x22;font-semibold\&#x22;>Submissions are paused</EmptyState.Title>\n    <EmptyState.Description>They reopen on Monday at 9:00.</EmptyState.Description>\n  </div>\n</EmptyState.Root>&#x22;">
  <EmptyState.Root className="text-sm" color="orange">
    <EmptyState.Icon color="orange" size="lg" radius="full">
      <Inbox className="iconStroke" />
    </EmptyState.Icon>

    <div>
      <EmptyState.Title className="font-semibold">
        Submissions are paused
      </EmptyState.Title>

      <EmptyState.Description>
        They reopen on Monday at 9:00.
      </EmptyState.Description>
    </div>
  </EmptyState.Root>
</Preview>

## In DataTable [#in-datatable]

`DataTable` renders its `empty` and `error` props as an `EmptyState`. The error view is red and the empty view neutral. Pass `{ title, description, actions, color }` to set the parts (`actions` becomes the children), and `color` to override a view's palette. See [DataTable's states](/docs/data-table#loading-empty--error-states).

## API [#api]

`EmptyState` accepts every `div` prop (`role`, `id`, `style`, …) plus:

<TypeTable
  type="{
  title: { type: &#x22;ReactNode&#x22;, required: true, description: &#x22;The headline: what the list shows instead of rows.&#x22; },
  icon: { type: &#x22;ReactNode&#x22;, description: &#x22;The glyph, drawn in a ThemeIcon (decorative, aria-hidden). Omitted or null, no badge.&#x22; },
  description: { type: &#x22;ReactNode&#x22;, description: &#x22;A muted line under the title: why, or what to do next. Stays muted whatever the color.&#x22; },
  children: { type: &#x22;ReactNode&#x22;, description: &#x22;The actions: buttons in a row under the text, which wraps on a narrow container. Under asChild, the child element's own content.&#x22; },
  color: { type: &#x22;Color&#x22;, description: &#x22;Tints the icon (a light ThemeIcon tile) and the title. Omitted, everything stays neutral.&#x22; },
  classNames: { type: &#x22;{ icon?, title?, description?, actions? }&#x22;, description: &#x22;A class per part, on top of the kit's.&#x22; },
  asChild: { type: &#x22;boolean&#x22;, default: &#x22;false&#x22;, description: &#x22;Render the block as its only child (e.g. the <li> of the list it stands in for), with the block's parts inside it and that element's own content as the actions.&#x22; },
  testId: { type: &#x22;string&#x22;, description: &#x22;Renders as data-testid on the root. See [Testing](/docs/testing).&#x22; },
}"
/>

The parts:

* `EmptyState.Root`: the centred column, which takes `color` and `testId`.
* `EmptyState.Icon`: a [`ThemeIcon`](/docs/theme-icon) that takes every one of its props. Its variant is `default` without a `color` and `light` with one.
* `EmptyState.Title` and `EmptyState.Description`: paragraphs.
* `EmptyState.Actions`: a centred row that wraps.

## Accessibility [#accessibility]

* The icon is decorative (`aria-hidden`). The title carries the meaning.
* Give an error `role="alert"`, so it is announced when it replaces the rows. An empty list that was empty from the start needs no role.
* The title is a paragraph, not a heading, so it doesn't add to the page outline. If the page's outline should list it, compose with your own heading inside `EmptyState.Root`.
