@tsparticles/astro

Official tsParticles Astro Component - Easily create highly customizable particle, confetti and fireworks animations and use them as animated backgrounds for your website. Ready to use components available also for Web Components, Vue.js (2.x and 3.x), An
4,336 8,995
Install
npm install @tsparticles/astro
Latest Version:4.4.0
License:MIT
Last Updated:Oct 23, 2026
Links: GitHub  ·  npm
Maintainer: matteobruni

banner

@tsparticles/astro

npm npm GitHub Sponsors

Official tsParticles Astro component

Discord Telegram

tsParticles Product Hunt

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:

  • id change → destroys the current container and reloads particles with the new id.
  • options change → destroys the current container and reloads particles with the new options.
  • url change → destroys the current container and reloads particles from the new url.
  • theme change → applies the theme via loadTheme without 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

tsParticle Website

Related Packages

@tsparticles/engine

Easily create highly customizable particle, confetti and fireworks animations an...

20,171,445 8,997
@tsparticles/basic

Basic tsParticles bundle — minimal core engine with only the essential features...

18,651,336 8,997
@tsparticles/slim

Slim tsParticles bundle — core engine with essential plugins, presets, and inter...

14,833,710 8,997
tsparticles

Full-featured tsParticles bundle — create stunning particle, confetti and firewo...

11,242,027 8,997
@tsparticles/confetti

tsParticles confetti bundle — easily create confetti, confetti cannon, confetti...

10,045,261 8,997

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
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