Confetti on Click Button Template

Celebrate user achievements and successful actions with a delightful burst of confetti.

This button is perfect for moments of celebration, such as completing a purchase, signing up for a service, or finishing a challenging task, creating a memorable and positive experience.

Screenshot of a celebratory button that triggers a confetti animation.

Get Source Code Preview

About the Confetti on Click Button

Adding a "surprise and delight" feature like a confetti explosion can make an application feel more human and engaging. It turns a standard, transactional moment into a small celebration. This effect will typically have the most impact when used sparingly for genuinely important and positive user actions. It associates a feeling of fun and reward with using your site or application.

Features

Dependencies & Code Breakdown

This component depends on an external JavaScript library called canvas-confetti. The library must be included in your page, for example via a CDN link in a script tag as shown in the template.

The JavaScript code first gets a reference to the button. It then adds a click event listener. Inside the listener, it calls the global confetti() function provided by the library. This function takes an options object where you can define the details of the animation. In this example, we set properties like particleCount and spread to create a "fireworks" effect originating from the center of the screen.

Code

Here is the complete code for the confetti on click button. Remember to include the canvas-confetti library for it to work.

View Output