Skip to content

Coin Flip

Pro

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.

  • Base UI
  • Motion
  • React 19
  • Tailwind CSS 4

Added Nov 11, 2026 · Pro license

Playground

Loading the preview

Props

Needs your Pro API key in GELATIN_UI_PRO_TOKEN. Set it up

Pro itemAPI key required

Coin Flip needs a Pro API key

Try the live preview for free. With Pro, the add command above puts the source in your project.

Files it adds
25
More Pro items, one API key
+327
Your coding agent runs it
1 cmd

$79$129once, for life

Already have Pro? Sign in to set up your API key.

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

who-pays.tsx

CoinFlip

<div>
PropTypeDefaultDescription
value"heads""tails"—The face that shows at rest. Controlled: the coin lands on its own pick, then asks for it.
defaultValue"heads""tails""heads"
onValueChange—Called when the coin comes to rest, with the face that shows.
onTossStart—Called when a toss starts: a press on the coin or the trigger that the coin takes.
disabledbooleanfalseStops new tosses. A toss in the air still lands.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

CoinFlipCoin

<button>
PropTypeDefaultDescription
classNamestring—
styleCSSProperties—
From Base UIButtonBase UI docs
focusableWhenDisabledbooleanfalseWhether the button should be focusable when disabled.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
nativeButtonbooleantrueWhether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
...props<button> attributes—Every other attribute goes to the <button>, with a ref.

CoinFlipHeads

<span>
PropTypeDefaultDescription
...props<span> attributes—Every other attribute goes to the <span>, with a ref.

CoinFlipTails

<span>
PropTypeDefaultDescription
...props<span> attributes—Every other attribute goes to the <span>, with a ref.

CoinFlipTrigger

<button>
PropTypeDefaultDescription
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"—
classNamestring—
busyboolean—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.
From Base UIButtonBase UI docs
focusableWhenDisabledbooleanfalseWhether the button should be focusable when disabled.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.

CoinFlipValue

<span>
PropTypeDefaultDescription
valueRequired"heads""tails"—The face this part waits for.
...props<span> attributes—Every other attribute goes to the <span>, with a ref.
  • 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.
  • For a plain on and off setting, use Switch.
  • For a pick between two named views, use Segmented Control.
  • For a random pick from more than two results, use Dice Roll.
EnterorSpaceTosses the coin when the coin or CoinFlipTrigger has focus. A press while the coin is in the air does nothing.

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.

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

Built with

Installs with Coin Flip

Components
Button
  1. AddedCoin Flip, with Button.
Open the release