---
title: "Dice Roll"
description: "3D dice that you throw into a felt tray with real physics: they spin, bounce, roll over their edges, and rock to rest on fair faces. d6 and d20."
url: https://gelatinui.com/components/dice-roll
markdown_url: https://gelatinui.com/components/dice-roll.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/dice-roll"
version: "2026-11-11"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Dice Roll

> 3D dice that you throw into a felt tray with real physics: they spin, bounce, roll over their edges, and rock to rest on fair faces. d6 and d20.

Page: https://gelatinui.com/components/dice-roll

## When to use it

Best for: A fair random roll that people want to watch: a game turn, a check, or a playful pick.

- Put one `DiceRollDie` in `DiceRollTray` for each die. Set `sides` to 6 or 20, and `variant` to `ivory`, `onyx`, or `ruby`.
- Read the faces in `onRollEnd`. It runs when every die is at rest, with the faces in the order the dice render.
- Use `onRollStart` to hide an old result or lock a choice while the dice roll. It runs once per throw.
- Show the sum with `DiceRollTotal`. Children go before the number (`Total `).
- Use your own text for game rules: modifiers, doubles, a natural 20.

## When not to use it

- For a fair pick between two results, use [Coin Flip](https://gelatinui.com/components/coin-flip.md).
- For a number that people type or step, use [Number Field](https://gelatinui.com/components/number-field.md).

## Notes for agents

- Each face is a fair pick from `crypto.getRandomValues` (by rejection). The physics only lands the die on it.
- The dice are not controlled: you cannot set a face. Before the first roll, d6 dice show 5, 3, 6, 2, 4, 1 in order, and a d20 shows 20; `onRollEnd` does not run for these.
- A die that joins or leaves in the air does not stop the roll. The others keep rolling.
- With no dice in the tray, the tray and `DiceRollTrigger` take no press, and `DiceRollTotal` shows nothing.
- Set the die size with `--dice-roll-size` on `DiceRollTray` (default 4rem). The dice get smaller when their lanes do not fit the tray width.
- With no children the root renders two ivory dice, the total, and a Roll dice button.

## Anatomy

```text
DiceRoll
├─ DiceRollTray (0..n)
├─ DiceRollDie (0..n)
├─ DiceRollTrigger (0..n)
└─ DiceRollTotal (0..n)
```

## API reference

### DiceRoll

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `onRollEnd` | `function` |  | Called when the dice come to rest, with their faces in the order the dice render. |
| `onRollStart` | `function` |  | Called when a throw starts: a press on the tray or the trigger that the dice take. |
| `disabled` | `boolean` | false | Stops new throws. A throw in the air still lands. |

### DiceRollTray

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `style` | `CSSProperties` |  |  |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### DiceRollDie

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `"ivory" \| "onyx" \| "ruby"` |  |  |
| `sides` | `DieSides` | 6 | A cube (6) or an icosahedron (20). |

### DiceRollTrigger

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "icon" \| "icon-lg" \| "icon-sm" \| "icon-xs" \| "lg" \| "sm" \| "xl" \| "xs"` |  |  |
| `variant` | `"dashed" \| "default" \| "destructive" \| "destructive-outline" \| "ghost" \| "link" \| "media" \| "outline" \| "secondary"` |  |  |
| `className` | `string` |  |  |
| `busy` | `boolean` |  | The button waits for the app (busy words): a spinner, `aria-busy`, and no clicks. Focus stays on the button. The style hook stays `data-loading`. |
| `spinnerPlacement` | `"center" \| "start"` |  | `center` (default): the spinner covers the label. `start`: it takes the leading icon slot. The icon sizes always use `center`, because their one icon is the label. |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### DiceRollTotal

No props of its own: `className`, `children`, and every other prop go to the element it renders.

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| DiceRoll | `dice-roll` |  |  |  |
| DiceRollTray | `dice-roll-tray` | `data-disabled`, `data-rolling` | `--dice-roll-count`, `--dice-roll-die`, `--dice-roll-size` |  |
| DiceRollDie | `dice-roll-die` | `data-joined` | `--dice-roll-die` |  |
| DiceRollTrigger | `dice-roll-trigger` |  |  |  |
| DiceRollTotal | `dice-roll-total` |  |  |  |

## Usage

Put the dice in the tray, then add the total and a trigger.

```tsx title="backgammon-turn.tsx"
import {
  DiceRoll,
  DiceRollDie,
  DiceRollTotal,
  DiceRollTray,
  DiceRollTrigger,
} from "@/components/pro/effects/dice-roll";

export function BackgammonTurn() {
  return (
    <DiceRoll onRollEnd={(values) => console.log(values)}>
      <DiceRollTray>
        <DiceRollDie />
        <DiceRollDie />
      </DiceRollTray>
      <DiceRollTotal>Move </DiceRollTotal>
      <DiceRollTrigger>Roll</DiceRollTrigger>
    </DiceRoll>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui-pro/dice-roll
```

It adds 27 registry items: 24 files, 5213 lines, and the npm packages `@base-ui/react`, `@xstate/react`, `clsx`, `motion`, `tailwind-merge`, `tailwind-variants`, `xstate`.

## Built on

- [Button](https://gelatinui.com/components/button.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Button](https://gelatinui.com/components/button.md)
- [Badge](https://gelatinui.com/components/badge.md)
- [Coin Flip](https://gelatinui.com/components/coin-flip.md)
- [Card](https://gelatinui.com/components/card.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Enter, Space | Throws the dice when the tray or `DiceRollTrigger` has focus. A press while the dice roll does nothing. |

## Accessibility

The tray is a button with the name "Roll the dice". Give it your own `aria-label` when the roll has a job.

Show the result as text (`DiceRollTotal` or your own line), not only as the faces of the dice.

The dice spin fast for about a second, then roll slower to rest. They do not flash.

## Motion

| Part | Motion |
| --- | --- |
| Throw | progress · about 1.5 s on one linear clock: an arc with spin, a bounce, rolls over the edges, and a rock to rest |
| Total | statusPop · the total pops in when the dice come to rest, and fades out on fadeExit when the next throw starts |
