# js-confetti

> JS Confetti library with zero dependencies, works without any config, TS typings included, adapts to user screen

Latest version **0.13.1** (published 2025-09-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install js-confetti
pnpm add js-confetti
yarn add js-confetti
bun add js-confetti
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.13.1 |
| Published | 2025-09-02 |
| First published | 2021-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 43.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1296 |
| Author | Vladimir Nikitin vladimirsuperwizard@gmail.com |
| Maintainers | loonywizard |
| Keywords | confetti, js-confetti |

## Links

- npm: https://www.npmjs.com/package/js-confetti
- Repository: https://github.com/loonywizard/js-confetti
- Issues: https://github.com/loonywizard/js-confetti/issues
- npm.io page: https://npm.io/package/js-confetti

## Recent versions

- 0.13.1 (latest) — 2025-09-02
- 0.13.0 — 2025-09-02
- 0.12.0-add-confetti-at-position-test — 2025-08-22
- 0.12.0 — 2023-12-08
- 0.11.0 — 2022-10-12
- 0.10.2 — 2021-12-22
- 0.10.1 — 2021-12-17
- 0.10.0 — 2021-12-02
- 0.9.1 — 2021-11-21
- 0.9.0 — 2021-07-24
- 0.8.0-add-custom-canvas-support — 2021-07-24
- 0.8.0 — 2021-06-29
- 0.7.1 — 2021-06-28
- 0.7.0 — 2021-06-26
- 0.6.1 — 2021-06-25
- … 29 more at https://npm.io/package/js-confetti/versions

## README

<img src="assets/app-demo.gif" width="600px" />


[![npm version](https://badge.fury.io/js/js-confetti.svg)](https://badge.fury.io/js/js-confetti)
![NPM Downloads](https://img.shields.io/npm/dw/js-confetti)
[![](https://data.jsdelivr.com/v1/package/npm/js-confetti/badge?style=rounded)](https://www.jsdelivr.com/package/npm/js-confetti)
![npm bundle size](https://img.shields.io/bundlephobia/minzip/js-confetti)

# 🎉 JavaScript Confetti library

💥 Supports emojis as confetti<br/>
⚡️ Zero dependencies used<br/>
🦄 Works without any config, yet configurable<br/>
🛠 Has TypeScript typings<br/>
🧩 Confetti speed adapts to user screen width

Links: [GitHub](https://github.com/loonywizard/js-confetti) | [NPM](https://www.npmjs.com/package/js-confetti) | [Demo](https://loonywizard.github.io/js-confetti/)


## Install

You can install library from NPM using yarn or npm

```sh
yarn add js-confetti
```

Alternatively you can download script from CDN
```html
<script src="https://cdn.jsdelivr.net/npm/js-confetti@latest/dist/js-confetti.browser.js"></script>
```

and then access `JSConfetti` global variable

## Usage

Initialize instance of JSConfetti class and call addConfetti method

```js
import JSConfetti from 'js-confetti'

const jsConfetti = new JSConfetti()

jsConfetti.addConfetti()
```

*NOTE* `new JSConfetti()` creates HTML Canvas element and adds it to page, so call it only once!

If need to use custom canvas element, you can pass `canvas` arg to JSConfetti constructor ([example](https://codepen.io/loonywizard-the-selector/pen/wvdPbGm))

```js
const canvas = document.getElementById('your_custom_canvas_id')

const jsConfetti = new JSConfetti({ canvas })
```

## Customise confetti

Use emojis as confetti:

```js
jsConfetti.addConfetti({
   emojis: ['🌈', '⚡️', '💥', '✨', '💫', '🌸'],
})
```

<br/>

Customize confetti colors:

```js
jsConfetti.addConfetti({
  confettiColors: [
    '#ff0a54', '#ff477e', '#ff7096', '#ff85a1', '#fbb1bd', '#f9bec7',
  ],
})
```

<br/>

Customize confetti radius:

```js
jsConfetti.addConfetti({
  confettiRadius: 6,
})
```

<br/>

Customize confetti number:

```js
jsConfetti.addConfetti({
  confettiRadius: 6,
  confettiNumber: 500,
})
```

<br/>

Combine different properties:

```js
jsConfetti.addConfetti({
  emojis: ['🦄'],
  emojiSize: 100,
  confettiNumber: 30,
})
```

## addConfettiAtPosition

example with dispatching confetti on mouse click - 
take X and Y position of the mouse from event and 
pass them in `confettiDispatchPosition` param.

all customisations work in this method as well!

```js
jsConfettiRef.addConfettiAtPosition({
  confettiDispatchPosition: {
    x: event.clientX,
    y: event.clientY
  }
})
```

## clearCanvas()

Call `clearCanvas` method to clear canvas

Example:

```js
const jsConfetti = new JSConfetti()

jsConfetti.addConfetti()

// ... 
jsConfetti.clearCanvas()
```

## addConfetti Promise

`addConfetti` method returns Promise, which is resolved when added confetti dissapears from the user screen due to the gravity physics of confetti

Example:

```js
// async/await
await jsConfetti.addConfetti()
console.log('Confetti animation completed!')

// Promise.then
jsConfetti.addConfetti()
   .then(() => console.log('Confetti animation completed!'))
```

## How to run locally

Install dependencies by Yarn or NPM
```sh
yarn install
```

Run `dev` script with website build
```sh
yarn run dev
```

## License
MIT

---
_Source: https://npm.io/package/js-confetti · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
