---
title: "Coin Flip"
description: "A 3D gold coin that you toss with real physics: it spins up, bounces on the table, and whirrs to rest like Euler's disk on a fair result."
url: https://gelatinui.com/components/coin-flip
markdown_url: https://gelatinui.com/components/coin-flip.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/coin-flip"
version: "2026-11-11"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Coin Flip

> A 3D gold coin that you toss with real physics: it spins up, bounces on the table, and whirrs to rest like Euler's disk on a fair result.

Page: https://gelatinui.com/components/coin-flip

## When to use it

Best for: A fair yes or no pick that people want to watch: a toss, a call, or who goes first.

- Put `CoinFlipHeads` and `CoinFlipTails` in `CoinFlipCoin`, and give each one the face art as an image.
- Show the result with `CoinFlipValue`: it shows when the coin lies on its face, and leaves when the next toss starts.
- Read each result in `onValueChange`, which runs when the coin comes to rest.
- Use `onTossStart` to hide an old result or lock a call while the coin is in the air. It runs once per toss.
- Leave about 1.5 coin sizes of room above the coin: the toss rises toward the viewer.

## When not to use it

- For a plain on and off setting, use [Switch](https://gelatinui.com/components/switch.md).
- For a pick between two named views, use [Segmented Control](https://gelatinui.com/components/segmented-control.md).
- For a random pick from more than two results, use [Dice Roll](https://gelatinui.com/components/dice-roll.md).

## Notes for agents

- The result is a fair bit from `crypto.getRandomValues`. The physics only lands the coin on it.
- `value` is controlled: the coin lands on its own pick, then calls `onValueChange`. A parent that keeps its old `value` turns the coin back after the toss.
- `CoinFlipValue` also shows at rest before the first toss (on `defaultValue`). Keep your own flag when a scene must hide the result until the first toss.
- `disabled` stops new tosses. A toss in the air still lands. The coin and the trigger keep their focus stop.
- Set the size with `--coin-flip-size` on `CoinFlipCoin` (default 10rem).
- With no children the root renders a drawn gold coin (H and T) and a Flip coin button.

## Anatomy

```text
CoinFlip
├─ CoinFlipCoin (0..n)
├─ CoinFlipHeads (0..n)
├─ CoinFlipTails (0..n)
├─ CoinFlipTrigger (0..n)
└─ CoinFlipValue (0..n)
```

## API reference

### CoinFlip

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `CoinFace` |  | The face that shows at rest. Controlled: the coin lands on its own pick, then asks for it. |
| `defaultValue` | `CoinFace` | "heads" |  |
| `onValueChange` | `function` |  | Called when the coin comes to rest, with the face that shows. |
| `onTossStart` | `function` |  | Called when a toss starts: a press on the coin or the trigger that the coin takes. |
| `disabled` | `boolean` | false | Stops new tosses. A toss in the air still lands. |

### CoinFlipCoin

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

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

### CoinFlipHeads

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

### CoinFlipTails

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

### CoinFlipTrigger

| 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

### CoinFlipValue

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `CoinFace` |  | The face this part waits for. |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| CoinFlip | `coin-flip` |  |  |  |
| CoinFlipCoin | `coin-flip-coin` | `data-disabled`, `data-flipping` | `--coin-flip-glint`, `--coin-flip-heads-shade`, `--coin-flip-size`, `--coin-flip-tails-shade` |  |
| CoinFlipHeads | `coin-flip-heads` |  | `--coin-flip-glint`, `--coin-flip-heads-shade`, `--coin-flip-size`, `--coin-flip-tails-shade` |  |
| CoinFlipTails | `coin-flip-tails` |  | `--coin-flip-glint`, `--coin-flip-heads-shade`, `--coin-flip-size`, `--coin-flip-tails-shade` |  |
| CoinFlipTrigger | `coin-flip-trigger` |  |  |  |
| CoinFlipValue | `coin-flip-value` |  |  |  |

## Usage

Put the two faces in the coin, then add the result and a trigger.

```tsx title="who-pays.tsx"
import {
  CoinFlip,
  CoinFlipCoin,
  CoinFlipHeads,
  CoinFlipTails,
  CoinFlipTrigger,
  CoinFlipValue,
} from "@/components/pro/effects/coin-flip";

export function WhoPays() {
  return (
    <CoinFlip onValueChange={(face) => console.log(face)}>
      <CoinFlipCoin>
        <CoinFlipHeads>
          <img src="/coin-heads.webp" alt="" />
        </CoinFlipHeads>
        <CoinFlipTails>
          <img src="/coin-tails.webp" alt="" />
        </CoinFlipTails>
      </CoinFlipCoin>
      <p>
        <CoinFlipValue value="heads">Heads: Maya pays</CoinFlipValue>
        <CoinFlipValue value="tails">Tails: Theo pays</CoinFlipValue>
      </p>
      <CoinFlipTrigger>Flip coin</CoinFlipTrigger>
    </CoinFlip>
  );
}
```

## 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/coin-flip
```

It adds 28 registry items: 25 files, 4629 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)
- [Dice Roll](https://gelatinui.com/components/dice-roll.md)
- [Card](https://gelatinui.com/components/card.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Enter, Space | Tosses the coin when the coin or `CoinFlipTrigger` has focus. A press while the coin is in the air does nothing. |

## Accessibility

The coin is a button with the name "Toss the coin". Give it your own `aria-label` when the toss has a job.

The result shows as text with `CoinFlipValue`, not only as the face on the coin.

The coin turns about 5 times a second, so it never flashes more than three times a second.

## Motion

| Part | Motion |
| --- | --- |
| Toss | progress · about 2.5 s on one linear clock: an arc with 5 turns a second, 2 or 3 bounces, and the Euler's disk settle |
| Result | statusPop · the result text pops in when the coin comes to rest, and fades out on fadeExit when the next toss starts |
