Skip to content

joseba-mirena/particles-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Particles ✨

Lightweight Canvas Animation Library.

Version License Size Live Demo

A simple, customizable particle system for web backgrounds, effects, and interactions.

Features

Particle Types

  • circle – default smooth circles
  • star – 5-pointed stars with caching for performance
  • confetti – rectangles with random aspect ratio
  • triangle – equilateral triangles
  • image – uses one or multiple images (URL or array)
  • emoji – renders emoji characters (string or array)

Animation Modes

  • flow – floating, bouncing particles with mouse repulsion & optional connections
  • rain – continuous falling particles from top (smooth recycling)
  • firework – occasional random bursts across the sky + click/touch explosions

Performance Optimizations

  • Viewport culling (skips off-screen particles)
  • Star shape caching (offscreen canvas)
  • Trail drawing throttled (every 3rd frame)
  • Delayed particle creation when using images (no fallback flash)

Other Capabilities

  • Mouse interaction (repulsion/gravity-like push)
  • Trails on bursts/fireworks
  • Rainbow colors or custom palette
  • Connect nearby particles with lines
  • Responsive (auto-resizes with window)

Installation

Add the minified version before the closing </body> tag:

<script 
    src="https://opensource.josebamirena.com/particles/1.0.0/dist/particles.min.js" 
    integrity="sha384-ovQETGtGwaVATmqCOoMNIo1bur9NDv5+pG2BzxOqa5/M7BvYh3XhYjG607gXu/7D" 
    crossorigin="anonymous">
</script>
    <div id="particles-container" aria-hidden="true"></div>
// CSS
#particles-container {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
}

#particles-container canvas {
  /* clicks reach canvas */
  pointer-events: auto;
  display: block;
  width: 100%;
  height: 100%;
}

Particles defaults

    <script>
        const defaults = {
            container: 'particles-container', // Particles renderization background ID
            type: 'circle', // 'circle', 'star', 'confetti', 'triangle', 'image', 'emoji'
            mode: 'flow', // 'flow', 'rain', 'firework'
            imageUrl: null, // string or array (mandatory for type image)
            emoji: null, // string or array (mandatory for type emoji)
            count: 80,
            colors: ['#ff006e', '#8338ec', '#3a86ff', '#ffbe0b', '#fb5607'],
            useRainbow: false,
            burst: false,
            sizeMin: 5,
            sizeMax: 12,
            speed: 1.0,
            connect: false,
            connectDistance: 120,
            connectOpacity: 0.6,
            grabRadius: 100,
            opacity: 0.85,
            backgroundParticles: true,
            gravity: 0.08,
            rotationSpeed: 0.03,
            spawnRate: 0.005,
            trails: false,
            trailLength: 16,
            trailOpacity: 0.6,
        };
    </script>

Particles Basic Usage

<script>
    Particles.init({
        container: 'my-html-container-id', // particles-container by default
        type: 'circle',
        mode: 'flow',
        count: 120,
        sizeMin: 4,
        sizeMax: 12,
        opacity: 0.8,
        gravity: 0.05,
        backgroundParticles: true,
        trails: false,
    });
</script>

Particles examples

Stars fireworks

<script>
    Particles.init({ 
        type: 'star', 
        mode: 'firework', 
        spawnRate: 0.025, 
        trails: true 
    });
</script>

Colorful ADN circles

<script>
    Particles.init({ 
        type: 'circle', 
        burst: false, 
        connect: true, 
        connectOpacity: 0.90, 
        connectDistance: 130 
    });
</script>

Floating colorful stars

<script>
    Particles.init({
        type: 'star',
        mode: 'flow',
        count: 140,
        sizeMin: 5,
        sizeMax: 14,
        colors: ['#ffffff', '#ffe066', '#ff99cc'],
        opacity: 0.9,
        connect: true,
        connectDistance: 140,
        connectOpacity: 0.25,
    });
</script>

Smooth falling confetti rain

<script>
    Particles.init({
        type: 'confetti',
        mode: 'rain',
        count: 180,
        sizeMin: 6,
        sizeMax: 18,
        gravity: 0.18,
        rotationSpeed: 0.05,
        opacity: 0.92,
    });
</script>

Rocket emoji floating around

<script>
    Particles.init({
        type: 'emoji',
        emoji: '🚀',
        mode: 'flow',
        count: 80,
        sizeMin: 18,
        sizeMax: 38,
        opacity: 0.95,
        gravity: 0.02,
        rotationSpeed: 0.04,
    });
</script>

Mixed emoji rain

<script>
    Particles.init({
        type: 'emoji',
        emoji: ['🎉', '✨', '💥', '🌈', '🔥'],
        mode: 'rain',
        count: 150,
        sizeMin: 20,
        sizeMax: 45,
        gravity: 0.12,
        rotationSpeed: 0.06,
    });
</script>

🎯 Live Demo

Try Particles JS live on my website:
👉 Particles JS Demo

See floating stars, confetti rain, rocket emojis, and fireworks in action.

About

Open Source customizable particle animation library. Multiple particle types (circles, stars, confetti, emojis, images), three animation modes, mouse interaction, trails, and connections. Vanilla JS, zero dependencies.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors