# Density

Compact by default for a mouse, larger by itself on touch. Step down a size only where many controls share a row.

API [Button](/ui/storybook/?path=/docs/ui-primitives-button--docs) [Select](/ui/storybook/?path=/docs/ui-primitives-select--docs) [Card](/ui/storybook/?path=/docs/ui-primitives-card--docs) [DropdownMenu](/ui/storybook/?path=/docs/ui-primitives-dropdownmenu--docs) [Tooltip](/ui/storybook/?path=/docs/ui-primitives-tooltip--docs)

**Use the default size, step down only inside a dense row or toolbar, and leave touch to the components.** The default is drawn for a mouse, so a screen shows as much of the work as it can; on a coarse pointer the same controls, drawn the same, take hit areas and room between them without the app asking.

```tsx
import { CI_RUN } from "@orz/fixtures/ci-run.ts";
import { Button } from "@orz/ui/components/button";
import {
  Card,
  CardAction,
  CardContent,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@orz/ui/components/card";
import { List, ListItem } from "@orz/ui/components/list";
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@orz/ui/components/tooltip";
import {
  CircleCheckIcon,
  CircleXIcon,
  PlayIcon,
  RefreshCwIcon,
  ScrollTextIcon,
} from "lucide-react";

export function CiRunPanel() {
  return (
    <TooltipProvider>
      <Card>
        <CardHeader>
          <CardTitle className="flex min-w-0 items-center gap-2">
            <CircleXIcon
              aria-label="failed"
              className="size-4 shrink-0 text-destructive"
            />
            <span className="truncate">
              {CI_RUN.workflow} #{CI_RUN.id}
            </span>
          </CardTitle>
          <CardAction>
            <Button variant="outline" size="sm">
              <PlayIcon data-icon="inline-start" /> Recording
            </Button>
            <Tooltip>
              <TooltipTrigger asChild>
                <Button variant="ghost" size="icon-sm" aria-label="Refresh">
                  <RefreshCwIcon />
                </Button>
              </TooltipTrigger>
              <TooltipContent>Refresh</TooltipContent>
            </Tooltip>
          </CardAction>
        </CardHeader>
        <CardContent>
          <List purpose="collection">
            <ul>
              {CI_RUN.jobs.map((job) => (
                <ListItem key={job.id} asChild>
                  <li className="flex min-h-row items-center gap-2 text-ui touch:min-h-touch">
                    {job.status === "failed" ? (
                      <CircleXIcon
                        aria-label="failed"
                        className="size-4 shrink-0 text-destructive"
                      />
                    ) : (
                      <CircleCheckIcon
                        aria-label="passed"
                        className="size-4 shrink-0 text-success"
                      />
                    )}
                    <span className="min-w-0 flex-1 truncate">{job.name}</span>
                    <span className="text-muted-foreground text-ui-sm tabular-nums">
                      {job.duration}s
                    </span>
                    <Button
                      variant="ghost"
                      size="xs"
                      aria-label={`Log for ${job.name}`}
                    >
                      <ScrollTextIcon data-icon="inline-start" /> Log
                    </Button>
                  </li>
                </ListItem>
              ))}
            </ul>
          </List>
        </CardContent>
        <CardFooter className="justify-end gap-2">
          <Button variant="outline">Re-run all jobs</Button>
          <Button>Re-run failed jobs</Button>
        </CardFooter>
      </Card>
    </TooltipProvider>
  );
}
```

The run's toolbar and each job's **Log** are a size down, because they repeat and sit next to content; the two actions that close out the panel are the default size. Press **Touch** above the example to see the same tree make room for a thumb.

## Sizes

Every number on this page is the default style's. Another [style](/ui/guidelines/foundations/styles/index.md) draws the same sizes at its own heights, and a coarse pointer adds the same room around them all the same. Every size of `Button`, as the default style draws it:

| Size                                    | Height                  | Use                                                                             |
| --------------------------------------- | ----------------------- | ------------------------------------------------------------------------------- |
| `lg`                                    | 32px                    | The one action a page or empty state is for; a call to action on a landing page |
| default                                 | 28px                    | Forms, dialogs, a panel's own actions: anything a person reads before pressing  |
| `sm`                                    | 24px                    | A toolbar of text buttons, a filter row, actions inside a card                  |
| `xs`                                    | 22px                    | An action repeated on every row of a list or table, inline with text            |
| `icon`, `icon-sm`, `icon-xs`, `icon-lg` | 28, 24, 22, 32px square | The icon-only counterparts of the four                                          |

```tsx
import { type AccessToken, TOKENS } from "@orz/fixtures/account.ts";
import { CI_RUN, type CiJob } from "@orz/fixtures/ci-run.ts";
import { Button } from "@orz/ui/components/button";
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@orz/ui/components/tooltip";
import {
  ArchiveIcon,
  PlayIcon,
  ScrollTextIcon,
  SquarePenIcon,
} from "lucide-react";

const TOKEN = TOKENS[0] as AccessToken;
const JOB = CI_RUN.jobs[0] as CiJob;
const ICON_SIZES = ["icon-lg", "icon", "icon-sm", "icon-xs"] as const;

export function ButtonSizes() {
  return (
    <TooltipProvider>
      <dl className="grid grid-cols-[4.5rem_1fr] items-center gap-x-4 gap-y-4 text-ui touch:[&>dd]:min-h-touch">
        <dt className="font-mono text-muted-foreground text-ui-sm">lg</dt>
        <dd>
          <Button size="lg">
            <SquarePenIcon data-icon="inline-start" /> Compose
          </Button>
        </dd>
        <dt className="font-mono text-muted-foreground text-ui-sm">default</dt>
        <dd className="flex flex-wrap gap-2 touch:gap-y-[calc(2*var(--spacing-hit))]">
          <Button variant="outline">Discard changes</Button>
          <Button>Save profile</Button>
        </dd>
        <dt className="font-mono text-muted-foreground text-ui-sm">sm</dt>
        <dd className="flex min-w-0 flex-wrap items-center gap-2">
          <Button variant="outline" size="sm">
            <PlayIcon data-icon="inline-start" /> Recording
          </Button>
          <Button
            variant="destructive"
            size="sm"
            aria-label={`Revoke ${TOKEN.name}`}
          >
            Revoke…
          </Button>
        </dd>
        <dt className="font-mono text-muted-foreground text-ui-sm">xs</dt>
        <dd className="flex min-w-0 items-center gap-2">
          <span className="min-w-0 truncate">{JOB.name}</span>
          <Button variant="ghost" size="xs" aria-label={`Log for ${JOB.name}`}>
            <ScrollTextIcon data-icon="inline-start" /> Log
          </Button>
        </dd>
        <dt className="font-mono text-muted-foreground text-ui-sm">icon-*</dt>
        <dd className="flex items-center gap-2">
          {ICON_SIZES.map((size) => (
            <Tooltip key={size}>
              <TooltipTrigger asChild>
                <Button variant="ghost" size={size} aria-label="Archive">
                  <ArchiveIcon />
                </Button>
              </TooltipTrigger>
              <TooltipContent>Archive</TooltipContent>
            </Tooltip>
          ))}
        </dd>
      </dl>
    </TooltipProvider>
  );
}
```

Each size where a demo uses it: **Compose** on Mail's phone layout, the profile form's buttons in Settings, **Recording** above a pull request's test log and **Revoke…** on each access token, each job's **Log** in the panel above, and **Archive** at every icon size.

`Input` and `Select`'s trigger are 28px, the default, so a field and its button line up on one row. `Select`'s trigger also comes in `sm` for a toolbar.

Controls side by side in one row take one size, so their tops and bottoms line up in every style: a `SegmentedControl` takes `size` as a `Button` does, and beside `sm` buttons is `sm` too; next to a field, which has only the default size, a button keeps the default. A `Toolbar` gives every part in it the bar's `size`, so a row of commands, with a segmented control among them, is one `Toolbar` rather than parts sized one by one, as the bar over each demo is.

**Do**

Keep the default size and let a coarse pointer add the room around it. One layout serves the mouse and the thumb.

**Don't**

Pass `size="lg"` when the screen is narrow, or branch on width to make touch targets. A narrow window on a desktop is still clicked, and a tablet is wide and still touched.

## Information density

- A row holds one primary line in `text-ui` and at most one secondary line in `text-ui-sm`. More than that belongs in the detail view.
- Repeated per-row actions are small and quiet (`ghost`, `xs`). One that destroys and asks first is `destructive` at `sm`, whose tint stays quiet until it is needed: the Settings demo's **Revoke…** on each token. A single action for the whole view is default size and stands apart.
- On a pointer, a row's secondary actions can wait in a `DropdownMenu` behind a `⋯` button; they are not hidden until hover, which leaves keyboard and touch users nothing to press.
- Dense is not cramped: rows keep `gap-2` between their parts and a 28px row height with a mouse, so a misclick lands on the right row.

```tsx
import {
  INBOX_PEOPLE,
  INBOX_THREADS,
  type InboxThread,
} from "@orz/fixtures/inbox.ts";
import { Button } from "@orz/ui/components/button";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from "@orz/ui/components/dropdown-menu";
import { List, ListItem } from "@orz/ui/components/list";
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@orz/ui/components/tooltip";
import { cn } from "@orz/ui/lib/utils";
import {
  ArchiveIcon,
  EllipsisIcon,
  MailIcon,
  MailOpenIcon,
  SquarePenIcon,
  Trash2Icon,
} from "lucide-react";
import { useState } from "react";
import { toast } from "sonner";

const INBOX = INBOX_THREADS.filter((thread) => !thread.folder).slice(0, 4);

const senders = (thread: InboxThread) =>
  [...new Set(thread.messages.map((message) => message.from))]
    .map((login) => INBOX_PEOPLE[login] ?? login)
    .join(", ");

export function ThreadRows() {
  const [threads, setThreads] = useState(INBOX);
  const change = (next: InboxThread[], message: string) => {
    const before = threads;
    setThreads(next);
    toast(message, {
      action: { label: "Undo", onClick: () => setThreads(before) },
    });
  };
  const remove = (id: string, message: string) =>
    change(
      threads.filter((thread) => thread.id !== id),
      message,
    );
  return (
    <TooltipProvider>
      <div className="grid gap-3">
        <div className="flex items-center justify-between gap-2">
          <h3 className="font-medium text-ui">Inbox</h3>
          <Button>
            <SquarePenIcon data-icon="inline-start" /> Compose
          </Button>
        </div>
        <List purpose="collection">
          <ul aria-label="Conversations">
            {threads.map((thread) => (
              <ListItem key={thread.id} asChild>
                <li className="flex min-h-row items-center gap-2 px-2 py-1 touch:min-h-touch">
                  <div className="grid min-w-0 flex-1">
                    <span
                      className={cn(
                        "truncate text-ui",
                        thread.unread && "font-semibold",
                      )}
                    >
                      {thread.unread && (
                        <span className="sr-only">Unread: </span>
                      )}
                      {thread.subject}
                    </span>
                    <span className="truncate text-muted-foreground text-ui-sm">
                      {senders(thread)}
                    </span>
                  </div>
                  <DropdownMenu>
                    <Tooltip>
                      <TooltipTrigger asChild>
                        <DropdownMenuTrigger asChild>
                          <Button
                            variant="ghost"
                            size="icon-xs"
                            aria-label={`More actions for “${thread.subject}”`}
                          >
                            <EllipsisIcon />
                          </Button>
                        </DropdownMenuTrigger>
                      </TooltipTrigger>
                      <TooltipContent>More actions</TooltipContent>
                    </Tooltip>
                    <DropdownMenuContent align="end" className="w-44">
                      <DropdownMenuItem
                        onSelect={() =>
                          remove(thread.id, "Conversation archived")
                        }
                      >
                        <ArchiveIcon /> Archive
                      </DropdownMenuItem>
                      <DropdownMenuItem
                        onSelect={() =>
                          change(
                            threads.map((each) =>
                              each.id === thread.id
                                ? { ...each, unread: !each.unread }
                                : each,
                            ),
                            `Conversation marked as ${thread.unread ? "read" : "unread"}`,
                          )
                        }
                      >
                        {thread.unread ? <MailOpenIcon /> : <MailIcon />}
                        {thread.unread ? "Mark as read" : "Mark as unread"}
                      </DropdownMenuItem>
                      <DropdownMenuSeparator />
                      <DropdownMenuItem
                        variant="destructive"
                        onSelect={() =>
                          remove(thread.id, "Conversation moved to Trash")
                        }
                      >
                        <Trash2Icon /> Delete
                      </DropdownMenuItem>
                    </DropdownMenuContent>
                  </DropdownMenu>
                </li>
              </ListItem>
            ))}
          </ul>
        </List>
      </div>
    </TooltipProvider>
  );
}
```

Each conversation is a subject over its senders. Its actions wait behind a quiet `⋯` that is always there, and **Compose**, the one action for the whole list, is the default size above it. Archive a conversation, then press **Undo** in the toast.

## On each platform

- **Pointer.** The sizes above. Neighbouring controls can sit 4px apart; a mouse lands reliably on a target of WCAG's 24px minimum ([2.5.8](https://www.w3.org/WAI/WCAG22/Understanding/target-size-minimum.html)).
- **Touch.** On a coarse pointer `@orz/ui`'s `touch:` variant keeps each control as it is drawn, gives it an invisible 36px hit area, and keeps neighbouring targets that far apart: between the 28pt Apple allows and the 44pt it gives a control by default ([Apple HIG: Accessibility](https://developer.apple.com/design/human-interface-guidelines/accessibility)), and never below that 24px minimum. [Touch & mobile](/ui/guidelines/platforms/touch-and-mobile/index.md) has the size of each part. A row you build yourself makes the room the same way: `touch:min-h-touch`.

## In the demos

- [Tasks](/ui/demos/tasks/index.md): A table row is a key, a title and its badges, with the row's ⋯ always drawn. Press Touch in the bar above, and the rows make room for a thumb around their controls.
- [Mail](/ui/demos/mail/index.md): A row is a sender, a subject and one line of snippet. Press Touch in the bar above, and the toolbars and the checkboxes make room for a thumb with no layout of their own.
