# Confetti

> Fire a burst of confetti from a button, an element, or any point, drawn on a temporary canvas overlay.

Source: https://www.honestui.com/docs/animated/confetti

```tsx
"use client";

import { PartyPopper } from "honestui/icons";

import { confetti, ConfettiButton } from "@/registry/default/animated/confetti";

function fireFromSides() {
  const y = window.innerHeight * 0.7;
  const shared = { particleCount: 60, spread: 55, startVelocity: 16 };
  void confetti({ ...shared, origin: { x: 0, y }, angle: 60 });
  void confetti({ ...shared, origin: { x: window.innerWidth, y }, angle: 120 });
}

export function ConfettiDemo() {
  return (
    <div className="w-80 rounded-xl border border-border bg-card p-5">
      <span className="grid size-8 place-items-center rounded-lg border border-border text-muted-foreground">
        <PartyPopper className="size-4" />
      </span>
      <h3 className="mt-5 text-base font-semibold tracking-tight text-foreground">Project shipped</h3>
      <p className="mt-1.5 text-sm leading-6 text-muted-foreground">
        All 24 tasks are done. Mark the milestone and let the team know.
      </p>
      <div className="mt-5 flex gap-2">
        <ConfettiButton className="bg-foreground text-background hover:bg-foreground/90">Celebrate</ConfettiButton>
        <button
          type="button"
          onClick={fireFromSides}
          className="inline-flex h-9 items-center rounded-md border border-border px-3.5 text-[13px] font-medium text-foreground transition-colors hover:bg-muted"
        >
          From the sides
        </button>
      </div>
    </div>
  );
}

```

## Overview [#overview]

Confetti marks a real accomplishment: a project shipped, a first payment received, a long task finished. Call `confetti()` from any event handler, use the `useConfetti` hook to burst from an element you hold a ref to, or drop in `ConfettiButton`, which bursts from its own center when clicked.

Pieces are drawn on one shared canvas that covers the viewport. The canvas is created on the first burst and removed as soon as the last piece has fallen, so nothing stays on the page between celebrations. The motion is measured in 60fps frames, so it looks the same on high refresh rate screens. `confetti()` returns a promise that resolves when the pieces are gone.

## Installation [#installation]

<CliBlock commands="[&#x22;confetti&#x22;]" />

## Usage [#usage]

```tsx
import { confetti, ConfettiButton, useConfetti } from "@/components/animated/confetti"

// A button that bursts from itself
<ConfettiButton>Celebrate</ConfettiButton>

// Any element
const [ref, fire] = useConfetti<HTMLDivElement>({ particleCount: 60 })
<div ref={ref} onClick={() => fire()}>Done</div>

// Any point, for example both sides of the screen
confetti({ origin: { x: 0, y: window.innerHeight * 0.7 }, angle: 60 })
confetti({ origin: { x: window.innerWidth, y: window.innerHeight * 0.7 }, angle: 120 })
```

Colors accept any canvas color string. A CSS variable such as `var(--primary)` is resolved against the document when the burst fires.

## Accessibility [#accessibility]

The canvas is hidden from assistive technology and never receives pointer events, so it cannot block the interface. Pair a burst with a visible message, because the confetti itself says nothing. When the user prefers reduced motion, bursts are skipped by default; set `disableForReducedMotion` to `false` only when the celebration carries meaning that is not shown elsewhere.

Use confetti rarely. A burst on every save turns into noise and slows the page.

## API Reference [#api-reference]

`confetti(options)` and the function returned by `useConfetti` accept:


  ### `element`

type: `Element | null`

Element to burst from, using its center. Takes precedence over 

    `origin`

    .

  ### `origin`

type: `{ x: number; y: number }`

Viewport point in CSS px. Defaults to the center of the viewport.

  ### `particleCount`

type: `number` · default: `80`

Number of pieces.

  ### `angle`

type: `number` · default: `90`

Launch direction in degrees: 90 is straight up.

  ### `spread`

type: `number` · default: `70`

Width of the launch cone in degrees.

  ### `startVelocity`

type: `number` · default: `11`

Launch speed.

  ### `gravity`

type: `number` · default: `0.32`

Downward pull.

  ### `decay`

type: `number` · default: `0.93`

Share of velocity kept each frame. Lower values stop pieces sooner.

  ### `drift`

type: `number` · default: `0`

Sideways wind.

  ### `ticks`

type: `number` · default: `170`

Lifetime of each piece in 60fps frames.

  ### `colors`

type: `string[]`

Piece colors.

  ### `shapes`

type: `(&#x22;square&#x22; | &#x22;circle&#x22; | &#x22;strip&#x22;)[]`

Piece shapes, picked at random.

  ### `scalar`

type: `number` · default: `1`

Size multiplier.

  ### `disableForReducedMotion`

type: `boolean` · default: `true`

Skip the burst under reduced motion.

  ### `zIndex`

type: `number` · default: `100`

z-index of the overlay canvas.


`useConfetti(defaults)` returns `[ref, fire]`. `ConfettiButton` accepts every `button` prop plus `options`.
