tsparticles
tsParticles - Easily create highly customizable JavaScript particles effects, confetti explosions and fireworks animations and use them as animated backgrounds for your website. Ready to use components available for React.js, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Inferno, Solid, Riot and Web Components.
Top Related Projects
A lightweight JavaScript library for creating particles
JavaScript 3D Library.
The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.
A little library that can be used for bursting particles effects on buttons and other elements
JavaScript animation engine
Quick Overview
tsparticles is a lightweight and highly customizable particle effects library for web applications. It provides a wide range of particle animation effects that can be easily integrated into various web projects, including websites, games, and interactive visualizations.
Pros
- Highly Customizable: tsparticles offers a vast array of configuration options, allowing developers to fine-tune the particle effects to match their specific design and animation requirements.
- Performant: The library is designed to be lightweight and efficient, ensuring smooth performance even on low-end devices.
- Cross-Platform Compatibility: tsparticles works seamlessly across different browsers and platforms, making it a versatile choice for web development.
- Active Development and Community: The project has an active community of contributors and is regularly updated with new features and bug fixes.
Cons
- Learning Curve: While the library is relatively easy to use, the extensive customization options may require some time and effort to fully understand and leverage.
- Limited Particle Types: While tsparticles offers a good range of particle types, some developers may require more specialized or complex particle effects that are not currently available.
- Dependency on Canvas or WebGL: The library relies on either the HTML5 Canvas or WebGL for rendering, which may not be suitable for all web projects.
- Potential Performance Issues on Older Devices: While the library is designed to be performant, complex particle effects may still cause performance issues on older or less powerful devices.
Code Examples
Example 1: Basic Particle Effect
import { loadFull } from "tsparticles";
const particlesInit = async (main) => {
await loadFull(main);
};
const particlesOptions = {
particles: {
number: {
value: 80,
density: {
enable: true,
value_area: 800,
},
},
color: {
value: "#ffffff",
},
shape: {
type: "circle",
stroke: {
width: 0,
color: "#000000",
},
polygon: {
nb_sides: 5,
},
},
opacity: {
value: 0.5,
random: false,
anim: {
enable: false,
speed: 1,
opacity_min: 0.1,
sync: false,
},
},
size: {
value: 3,
random: true,
anim: {
enable: false,
speed: 40,
size_min: 0.1,
sync: false,
},
},
line_linked: {
enable: true,
distance: 150,
color: "#ffffff",
opacity: 0.4,
width: 1,
},
move: {
enable: true,
speed: 6,
direction: "none",
random: false,
straight: false,
out_mode: "out",
attract: {
enable: false,
rotateX: 600,
rotateY: 1200,
},
},
},
interactivity: {
detect_on: "canvas",
events: {
onhover: {
enable: true,
mode: "repulse",
},
onclick: {
enable: true,
mode: "push",
},
resize: true,
},
modes: {
grab: {
distance: 400,
line_linked: {
opacity: 1,
},
},
bubble: {
distance: 400,
size: 40,
duration: 2,
opacity: 8,
speed: 3,
},
repulse: {
distance: 200,
},
push: {
particles_nb: 4,
},
remove: {
particles_nb: 2,
},
},
},
detectRetina: true,
};
const App = () => {
return (
<Particles
i
Competitor Comparisons
A lightweight JavaScript library for creating particles
Pros of particles.js
- Simpler and more lightweight, with a smaller file size
- Easier to set up and use for basic particle animations
- Well-established and widely used in many projects
Cons of particles.js
- Limited features and customization options compared to tsparticles
- No longer actively maintained, with the last update in 2018
- Lacks support for modern web technologies and frameworks
Code Comparison
particles.js:
particlesJS("particles-js", {
particles: {
number: { value: 80 },
color: { value: "#ffffff" },
shape: { type: "circle" }
}
});
tsparticles:
tsParticles.load("tsparticles", {
particles: {
number: { value: 80 },
color: { value: "#ffffff" },
shape: { type: "circle" },
move: { enable: true, speed: 6 }
}
});
Both libraries use similar configuration objects, but tsparticles offers more advanced options and features. tsparticles also provides better TypeScript support and integration with modern frameworks like React, Vue, and Angular. While particles.js is simpler to use for basic animations, tsparticles offers greater flexibility and ongoing development for more complex particle systems.
JavaScript 3D Library.
Pros of three.js
- More comprehensive 3D rendering capabilities
- Larger community and ecosystem
- Supports a wider range of 3D features (e.g., lighting, materials, textures)
Cons of three.js
- Steeper learning curve
- Larger file size and potentially higher performance overhead
- May be overkill for simple particle effects
Code Comparison
three.js:
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
tsParticles:
tsParticles.load("tsparticles", {
particles: {
number: { value: 80 },
color: { value: "#ffffff" },
shape: { type: "circle" },
move: { enable: true, speed: 6 }
}
});
three.js is a full-featured 3D library that offers extensive capabilities for creating complex 3D scenes and animations. It provides a wide range of tools for working with geometry, materials, lighting, and camera controls. However, this power comes with increased complexity and a steeper learning curve.
tsParticles, on the other hand, is specifically designed for creating particle effects and animations. It offers a simpler API and is more lightweight, making it easier to implement basic particle systems quickly. While it may not have the full 3D capabilities of three.js, it excels in its focused area of particle effects.
The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.
Pros of PixiJS
- More comprehensive 2D rendering engine with broader capabilities
- Larger community and ecosystem with extensive plugins and extensions
- Better performance for complex scenes and large numbers of objects
Cons of PixiJS
- Steeper learning curve due to its more extensive API
- Larger file size, which may impact load times for simpler projects
- Potentially overkill for basic particle effects or simple animations
Code Comparison
tsParticles:
tsParticles.load("tsparticles", {
particles: {
color: { value: "#ffffff" },
move: { enable: true, speed: 6 },
number: { value: 80 },
size: { value: 3 }
}
});
PixiJS:
const app = new PIXI.Application();
document.body.appendChild(app.view);
const particles = new PIXI.ParticleContainer(1000);
app.stage.addChild(particles);
// Additional setup for particle system
tsParticles is more focused on particle systems and provides a simpler API for creating particle effects. PixiJS offers a more comprehensive 2D rendering solution but requires more setup for particle systems. tsParticles is ideal for quick particle effects, while PixiJS is better suited for complex 2D graphics and games.
A little library that can be used for bursting particles effects on buttons and other elements
Pros of ParticleEffectsButtons
- Focused on button effects, providing specialized and visually appealing interactions
- Lightweight and easy to implement for specific use cases
- Includes creative and unique particle animations for buttons
Cons of ParticleEffectsButtons
- Limited to button interactions, less versatile than tsparticles
- Fewer customization options and configuration possibilities
- Less active development and community support
Code Comparison
ParticleEffectsButtons:
this.particles = [];
for (let i = 0; i < this.options.numParticles; i++) {
this.particles.push(new Particle(this));
}
tsparticles:
const particles = await loadParticlesEngine(tsParticles);
await particles.load("tsparticles", {
fpsLimit: 60,
particles: {
number: { value: 80, density: { enable: true, value_area: 800 } },
color: { value: "#ff0000" }
}
});
ParticleEffectsButtons focuses on creating particle effects specifically for button interactions, making it easier to implement in button-centric designs. However, it lacks the versatility and extensive customization options offered by tsparticles. tsparticles provides a more comprehensive particle system with broader applications and active community support, but may require more setup for simple button effects.
JavaScript animation engine
Pros of anime
- Lightweight and focused on animation, making it more suitable for simple animation tasks
- Easier to learn and implement for basic animations
- Supports a wider range of animation targets, including CSS properties and SVG attributes
Cons of anime
- Limited to animations only, lacking particle system functionality
- Less customizable for complex particle effects and interactions
- Smaller community and fewer updates compared to tsparticles
Code Comparison
anime:
anime({
targets: '.element',
translateX: 250,
rotate: '1turn',
duration: 800,
easing: 'easeInOutQuad'
});
tsparticles:
tsParticles.load("tsparticles", {
particles: {
number: { value: 80 },
color: { value: "#ff0000" },
shape: { type: "circle" },
move: { enable: true, speed: 6 }
}
});
Summary
While anime is a lightweight and easy-to-use animation library, tsparticles offers more comprehensive particle system functionality. anime is better suited for simple animations, while tsparticles excels in creating complex particle effects and interactions. The choice between the two depends on the specific requirements of your project.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
tsParticles - TypeScript Particles
A lightweight TypeScript library for creating particles. Dependency free (*), browser ready and compatible with React.js, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Inferno, Riot.js, Solid.js, and Web Components
Table of Contents
- tsParticles - TypeScript Particles
- Table of Contents
- Do you want to use it on your website?
- Library installation
- Official components for some of the most used frameworks
- Presets
- Templates and Resources
- Demo / Generator
- Video Tutorials
- Options
- Want to see it in action and try it?
- Migrating from Particles.js
- Plugins/Customizations
- Dependency Graph
- Sponsors
Do you want to use it on your website?
Documentation and Development references here ð
This library is available on two of the most popular CDNs and it's easy and ready to use, if you were using particles.js it's even easier.
You'll find the instructions below, with all the links you need, and don't be scared by TypeScript, it's just the source language.
The output files are just JavaScript. ð¤©
CDNs and npm
have all the sources you need in Javascript, a bundle browser ready (tsparticles.engine.min.js), and
all
files splitted for import
syntax.
If you are interested there are some simple instructions just below to guide you to migrate from the old particles.js library.
Library installation
Hosting / CDN
Please use these hosts or your own to load tsParticles on your projects
jsDelivr
cdnjs
unpkg
https://unpkg.com/@tsparticles/confetti/ https://unpkg.com/@tsparticles/engine/ https://unpkg.com/@tsparticles/fireworks/ https://unpkg.com/@tsparticles/basic/ https://unpkg.com/@tsparticles/slim/ https://unpkg.com/tsparticles/ https://unpkg.com/@tsparticles/all/
npm
tsParticles Confetti
tsParticles Engine
tsParticles Fireworks
tsParticles Basic
tsParticles Slim
tsParticles
tsParticles All
npm install @tsparticles/engine
yarn
yarn add @tsparticles/engine
pnpm
pnpm install @tsparticles/engine
Import and require
const tsParticles = require("@tsparticles/engine");
// or
import { tsParticles } from "@tsparticles/engine";
The imported tsParticles
is the same instance you have when including the script in the page using the <script>
tag.
Usage
Load tsParticles and configure the particles:
index.html
<div id="tsparticles"></div>
<script src="tsparticles.engine.min.js"></script>
app.js
// @path-json can be an object or an array, the first will be loaded directly, and the object from the array will be randomly selected
/* tsParticles.load(@params); */
tsParticles
.load({
id: "tsparticles",
url: "presets/default.json",
})
.then(container => {
console.log("callback - tsparticles config loaded");
})
.catch(error => {
console.error(error);
});
//or
tsParticles.load({
id: "tsparticles",
options: {
/* options here */
},
});
//or
tsParticles.load({
id: "tsparticles",
options: [
{
/* options here */
},
{
/* other options here */
},
],
});
//random object
tsParticles.load({
id: "tsparticles",
options: [
{
/* options here */
},
{
/* other options here */
},
],
index: 1,
}); //the second one
// Important! If the index is not in range 0...<array.length, the index will be ignored.
// after initialization this can be used.
/* tsParticles.setOnClickHandler(@callback); */
/* this will be fired from all particles loaded */
tsParticles.setOnClickHandler((event, particles) => {
/* custom on click handler */
});
// now you can control the animations too, it's possible to pause and resume the animations
// these methods don't change the config so you're safe with all your configurations
// domItem(0) returns the first tsParticles instance loaded in the dom
const particles = tsParticles.domItem(0);
// play will start the animations, if the move is not enabled it won't enable it, it just updates the frame
particles.play();
// pause will stop the animations
particles.pause();
Official components for some of the most used frameworks
Angular
@tsparticles/angular
Instructions available here
Astro
astro-particles
Instructions available here
Ember.js
ember-tsparticles
Instructions available here
Inferno
inferno-particles
Instructions available here
jQuery
jquery-particles
Instructions available here
Preact
preact-particles
Instructions available here
ReactJS
@tsparticles/react
Instructions available here
RiotJS
riot-particles
You can find the instructions here
SolidJS
solid-particles
You can find the instructions here
Svelte
@tsparticles/svelte
Instructions available here
VueJS 2.x
@tsparticles/vue2
Instructions available here
VueJS 3.x
@tsparticles/vue3
Instruction available here
Web Components
web-particles
You can find the instructions here
WordPress
@tsparticles/wordpress
The plugin page hosted on WordPress.org can be found here
Elementor
Actually, an official tsParticles plugin isn't existing, but I have a collaboration with
the Premium Addons for Elementor
plugin collection.
Use Premium Addons for Elementor Page Builder and get the chance to include tsParticles in your next WordPress website without the need to write a single line of code. See a Live Example.
Presets
There are some presets ready to be used in this repository, and they also have a bundle file that contains everything needed to run.
Big Circles
This preset loads big colored circles moving upwards on a white background.
You can find the instructions here
Bubbles
This preset loads colored bubbles coming from the bottom of the screen on a white background.
You can find the instructions here
Confetti
This preset loads white and red confetti launched from the screen center on a transparent background.
You can find the instructions here
Fire
This preset loads a faded red to a black background with particles colored like fire and ash sparks.
You can find the instructions here
Firefly
This preset loads a mouse trail made with small fading particles like little fireflies.
You can find the instructions here
Fireworks
This preset loads a beautiful fireworks effect.
You can find the instructions here
Fountain
You can find the instructions here
Links
You can find the instructions here
Sea Anemone
You can find the instructions here
Snow
You can find the instructions here
Stars
You can find the instructions here
Triangles
You can find the instructions here
Templates and Resources
You can find some tsParticles related templates here. The templates are created for Vanilla Javascript, ReactJS, VueJS, Angular, SvelteJS, and other frameworks.
The templates will vary, new ones can be created or older ones updated with the latest features or changed to a better style. Check them out once in a while.
If you created some good design with tsParticles feel free to submit a pull request with your cool template, you'll be credited as the template author!
https://github.com/tsparticles/templates
Demo / Generator
https://particles.js.org/samples
Video Tutorials
You can find all video tutorials on the website here: https://particles.js.org/video.html
More videos are coming soon! Check every day if there are some new contents.
Characters as particles
Polygon mask
Animated stars
Nyan cat flying on scrolling stars
Snow particles
Background Mask particles
particles.json
You can find some config samples here ð
Options
You can find all options available here ð
Want to see it in action and try it?
I've created a tsParticles collection on CodePen ð® or you can check out my profile
Otherwise, there's the demo page link below.
Want to see even more demos? Clone the repository on your computer and follow these instructions
$ pnpm i
$ pnpm run build
$ cd demo/vanilla
$ pnpm start
Boom! ð¥ http://localhost:3000 and you can check out other demos.
If you are brave enough you can switch to the dev
branch for trying the features under development.
Migrating from Particles.js
tsParticles has a package that makes this library 100% compatible with the particles.js configuration.
Seriously, you just need to change the script from particles.js to the bundled compatibility package, et-voilà , you're ready ð§!
You can read more here
Want to know 5 reasons to do the switch? Read here
Below you can find all the information you need to install tsParticles and its new syntax.
Plugins/Customizations
tsParticles now supports some customizations ð¥³.
You can create your own plugins
Read more here...
Dependency Graph
flowchart TD
subgraph core [Core]
engine[tsParticles Engine]
perlin-noise[Perlin Noise Lib]
simplex-noise[Simplex Noise Lib]
configs[tsParticles Configs]
end
subgraph bundle-basic [tsParticles Basic]
subgraph basic-movers [Movers]
move-base[Base]
end
subgraph basic-shapes [Shapes]
shape-circle[Circle]
end
subgraph basic-updates [Updaters]
updater-color[Color]
updater-opacity[Opacity]
updater-out-modes[Out Modes]
updater-size[Size]
end
end
engine --> bundle-basic
subgraph bundle-confetti [tsParticles Confetti]
subgraph confetti-plugins [Plugins]
plugin-emitters
plugin-motion
end
subgraph confetti-shapes [Shapes]
shape-cards
shape-emoji
shape-heart
shape-image
shape-polygon
shape-square
shape-star
end
subgraph confetti-updaters [Updaters]
updater-life
updater-roll
updater-rotate
updater-tilt
updater-wobble
end
end
bundle-basic --> bundle-confetti
subgraph bundle-slim [tsParticles Slim]
subgraph slim-interactions [Interactions]
subgraph slim-interactions-external [Externals]
interaction-external-attract[Attract]
interaction-external-bounce[Bounce]
interaction-external-bubble[Bubble]
interaction-external-connect[Connect]
interaction-external-grab[Grab]
interaction-external-pause[Pause]
interaction-external-push[Push]
interaction-external-remove[Remove]
interaction-external-repulse[Repulse]
interaction-external-slow[Slow]
end
subgraph slim-interactions-particles [Particles]
interaction-particles-attract[Attract]
interaction-particles-collisions[Collisions]
interaction-particles-links[Links]
end
end
subgraph slim-movers [Movers]
move-parallax[Parallax]
end
subgraph slim-plugins [Plugins]
subgraph slim-plugins-easings [Easings]
plugin-easing-quad[Quad]
end
end
subgraph slim-shapes [Shapes]
shape-emoji[Emoji]
shape-image[Image]
shape-line[Line]
shape-polygon[Polygon]
shape-square[Square]
shape-star[Star]
end
subgraph slim-updaters [Updaters]
updater-life[Life]
updater-rotate[Rotate]
updater-stroke-color[Stroke Color]
end
end
bundle-basic --> bundle-slim
subgraph bundle-fireworks [tsParticles Fireworks]
subgraph fireworks-effects [Effects]
effect-trail
end
subgraph fireworks-plugins [Plugins]
plugin-emitters
subgraph fireworks-plugin-emitters-shapes [Emitters Shapes]
plugin-emitters-shape-square
end
plugin-sounds
end
subgraph fireworks-updaters [Updaters]
updater-destroy
updater-life
updater-rotate
end
end
bundle-basic --> bundle-fireworks
subgraph bundle-full [tsParticles]
subgraph full-interactions [Interactions]
subgraph full-interactions-external [Externals]
interaction-external-trail[Trail]
end
end
subgraph full-plugins [Plugins]
plugin-absorbers[Absorbers]
plugin-emitters[Emitters]
subgraph full-plugin-emitters-shapes [Emitters Shapes]
plugin-emitters-shape-circle[Circle]
plugin-emitters-shape-square[Square]
end
end
subgraph full-shapes [Shapes]
shape-text[Text]
end
subgraph full-updaters [Updaters]
updater-destroy[Destroy]
updater-roll[Roll]
updater-tilt[Tilt]
updater-twinkle[Twinkle]
updater-wobble[Wobble]
end
end
bundle-slim --> bundle-full
subgraph bundle-all [tsParticles All]
bundle-pjs[tsParticles Particles.js Compatibility]
subgraph all-effects [Effects]
effect-bubble[Bubble]
effect-trail[Trail]
end
subgraph all-interactions [Interactions]
subgraph all-interactions-external [External]
interaction-external-particle[Particle]
interaction-external-pop[Pop]
end
interaction-light[Light]
subgraph all-interactions-particles [Particles]
interaction-particles-repulse[Repulse]
end
end
subgraph all-paths [Paths]
path-curl-noise[Curl Noise]
path-curves[Curves]
path-perlin-noise[Perlin Noise]
path-polygon[Polygon]
path-simplex-noise[Simplex Noise]
path-svg[SVG]
end
subgraph all-plugins [Plugins]
plugin-canvas-mask[Canvas Mask]
subgraph all-plugins-easings [Easings]
plugin-easing-back[Back]
plugin-easing-circ[Circ]
plugin-easing-cubic[Cubic]
plugin-easing-expo[Expo]
plugin-easing-linear[Linear]
plugin-easing-quart[Quart]
plugin-easing-quint[Quint]
plugin-easing-sine[Sine]
end
subgraph all-plugin-emitters-shapes [Emitters Shapes]
plugin-emitters-shape-canvas[Canvas]
plugin-emitters-shape-path[Path]
plugin-emitters-shape-polygon[Polygon]
end
subgraph all-plugins-exports [Exports]
plugin-export-image[Image]
plugin-export-json[JSON]
plugin-export-video[Video]
end
plugin-hsv-color[HSV Color]
plugin-infection[Infection]
plugin-motion[Motion]
plugin-poisson-disc[Poisson Disc]
plugin-polygon-mask[Polygon Mask]
plugin-sounds[Sounds]
end
subgraph all-shapes [Shapes]
shape-arrow[Arrow]
shape-cards[Cards]
shape-cog[Cog]
shape-heart[Heart]
shape-path[Path]
shape-rounded-polygon[Rounded Polygon]
shape-rounded-rect[Rounded Rect]
shape-spiral[Spiral]
end
subgraph all-updaters [Updaters]
updater-gradient[Gradient]
updater-orbit[Orbit]
end
simplex-noise --> path-curl-noise
perlin-noise --> path-perlin-noise
simplex-noise --> path-simplex-noise
end
bundle-full --> bundle-all
Sponsors
JetBrains
Huge thanks to JetBrains for the 2020-2022 Open Source Licenses!
JetBrains WebStorm is used to maintain this project.
Top Related Projects
A lightweight JavaScript library for creating particles
JavaScript 3D Library.
The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.
A little library that can be used for bursting particles effects on buttons and other elements
JavaScript animation engine
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot