@tsparticles/astro
| Install | |
|---|---|
npm install @tsparticles/astro |
|
| Latest Version: | 4.4.0 |
| License: | MIT |
| Last Updated: | Oct 23, 2026 |
| Links: | GitHub · npm |
@tsparticles/astro
Official tsParticles Astro component
Installation
npm install @tsparticles/astro
or
yarn add @tsparticles/astro
How to use
---
import Particles, { initParticlesEngine } from "@tsparticles/astro";
import { loadSlim } from "@tsparticles/slim";
import type { ISourceOptions } from "@tsparticles/engine";
await initParticlesEngine(async (engine) => {
await loadSlim(engine);
});
const options: ISourceOptions = {
background: {
color: {
value: "#000"
}
},
fullScreen: {
zIndex: -1,
},
particles: {
links: {
enable: true,
},
number: {
value: 100,
},
move: {
enable: true,
},
}
};
---
<script>
import type { Container } from "@tsparticles/engine";
window.particlesLoaded = function (container: Container) {
console.log("particlesLoaded callback");
};
</script>
<Particles id="tsparticles" options={options} loaded="particlesLoaded" />
Dev notes
When running the Astro demo in development, Vite/Astro may serve modules directly from the workspace and the browser needs a browser-ready ESM entry for the wrapper. To ensure the client runtime is initialized before the custom element upgrades, call initParticlesEngine on the client before the element is upgraded.
Recommended minimal pattern (client-side) — place this in your page before the
<script type="importmap">
{
"imports": {
"@tsparticles/astro": "/node_modules/@tsparticles/astro/dist/index.client.js",
"tsparticles": "/node_modules/tsparticles/esm/index.js"
}
}
</script>
<script type="module">
import { initParticlesEngine } from "@tsparticles/astro";
// Initialize the engine before the web component upgrades.
initParticlesEngine(async engine => {
const { loadFull } = await import("tsparticles");
await loadFull(engine);
}).catch(console.error);
</script>
Notes:
- The importmap above is a pragmatic development-time helper so the browser can resolve bare specifiers to the local node_modules dist files. In production builds a bundler or proper package exports should make this unnecessary.
- The important part is that initParticlesEngine is invoked (and begins initialization) before the custom element is defined/upgraded in the page so the component can detect the initialization and not throw.
Props
| Prop | Type | Definition |
|---|---|---|
| id | string | The id of the element. |
| loaded | string | The name of a global callback called once particles are loaded. |
| options | object | The options of the particles instance. |
| url | string | The remote options url, called using an AJAX request. |
| theme | string | The theme name to apply (requires @tsparticles/plugin-themes; safe no-op otherwise). |
Reactive updates
The component uses a connectedCallback / attributeChangedCallback pattern to react to attribute changes:
idchange → destroys the current container and reloads particles with the new id.optionschange → destroys the current container and reloads particles with the new options.urlchange → destroys the current container and reloads particles from the new url.themechange → applies the theme vialoadThemewithout a full reload (requires@tsparticles/plugin-themes; safe no-op when the plugin is missing).
On component teardown (disconnectedCallback) the container is destroyed, preventing orphan animations.
particles.json
Find all configuration options here.
You can find sample json configurations here 📖
Demos
Preset demos can be found here
There's also a CodePen collection actively maintained and updated here
Report bugs and issues here
Related Packages
Easily create highly customizable particle, confetti and fireworks animations an...
Basic tsParticles bundle — minimal core engine with only the essential features...
Slim tsParticles bundle — core engine with essential plugins, presets, and inter...
Full-featured tsParticles bundle — create stunning particle, confetti and firewo...
tsParticles confetti bundle — easily create confetti, confetti cannon, confetti...
Version History
| Version | Released | License |
|---|---|---|
| 4.4.0 | MIT | |
| 4.3.2 | MIT | |
| 4.3.1 | MIT | |
| 4.3.0 | MIT | |
| 4.2.1 | MIT | |
| 4.2.0 | MIT | |
| 4.1.3 | MIT | |
| 4.1.2 | MIT | |
| 4.1.1 | MIT | |
| 4.1.0 | MIT | |
| 4.0.5 | MIT | |
| 4.0.4 | MIT | |
| 4.0.3 | MIT | |
| 4.0.2 | MIT | |
| 4.0.1 | MIT | |
| 4.0.0 | MIT |
Pre-releases (4)
| Version | Released | License |
|---|---|---|
| 4.0.0-beta.17 | MIT | |
| 4.0.0-beta.16 | MIT | |
| 4.0.0-beta.15 | MIT | |
| 4.0.0-beta.12 | MIT |


