Click Spark

Posted on January 2, 2024
Takes about 2 minutes to read

Last week I had made this fun little experiment. When clicking or tapping on the page, sparks (of joy) fly out from the mouse cursor/tap position. It started with me just messing around a bit in CodePen, but after sharing and getting a few friendly nudges on my Mastodon post, this fun little experiment evolved into the <click-spark> Web Component which is now available in a GitHub repo.

Try it out in the CodePen demo below.

Open CodePen demo

The spark color can be modified by setting a color value to the --click-spark-color custom property:

<click-spark style="--click-spark-color: hotpink"></click-spark>

Updated on January 5th, 2023 — I had been thinking about a case where I'd like to have click sparks, but only when clicking on particular elements. I've updated the code so that an active-on attribute can be set on the custom element to target a comma-separated list of selectors. If any of the selectors match, let the sparks fly. Here's a CodePen demo of the following example.

<click-spark active-on=".send-sparks, #i-love-sparks, [data-sparks]"></click-spark>

Have your sparks your way. ✨

Back to all blog posts