# <particles>

Particles moved by formulas and drawn natively: presets like snow and confetti, or your own motion.

Category: Display.

```ham
<stack style="w-full h-320 rounded-xl bg-#070B1A">
    <particles count="700"
               x="w/2 + cos(i*0.137 + t*0.3) * (6 + i*0.2)"
               y="h/2 + sin(i*0.137 + t*0.3) * (6 + i*0.2) * 0.55"
               size="1.5 + rand*2.5"
               shape="glow"
               blend="add"
               color="hsl(200 + i*0.15, 90%, 70%)"
               style="w-full h-full"/>
</stack>
```

How Hype Apps draws it on a phone: [light](https://hypeapps.dev/img/tags/particles-light.webp), [dark](https://hypeapps.dev/img/tags/particles-dark.webp).

## Attributes

| Name | What it does | Default |
|---|---|---|
| `autostart` | false: nothing is emitted until #id.start. | `true` |
| `ax` | Acceleration px/s² (wind: ax="$wind"). |  |
| `ay` | Acceleration px/s² (gravity: ay="900"). |  |
| `blend` | add: overlapping particles brighten (light, fire). (normal, add) | `normal` |
| `bounce` | edge="bounce": the share of speed kept. | `0.6` |
| `burst` | How many #id.burst releases when it gives no number (60). |  |
| `chance` | A sub-emitter: the probability it fires at each event (a trail: at each emission). 0 never fires, 1 always does. | `1` |
| `color` | A color token, or hsl(h, s%, l%[, a]) / rgb(r, g, b[, a]) with formulas. Default white; a sub-emitter inherits its parent's. |  |
| `count` | Keep this many alive (respawned as they die). Default 50 with no rate or burst. On a sub-emitter: the burst at each event. |  |
| `drag` | Share of velocity lost per second, 0–1 (above 1, every particle stops at once). |  |
| `edge` | At the box edge: kill (default with velocity), wrap, bounce, none (default with x and y formulas). (kill, wrap, bounce, none) |  |
| `height` | Height in px when the parent gives none (200). |  |
| `lifetime` | Seconds, evaluated at birth (2 + rand). None: it lives until an edge removes it. |  |
| `max` | The most alive at once, sub-emitters included (at most 5000). | `1000` |
| `offscreen` | Off screen the effect pauses. wait: a burst sent then waits and plays once a third of the effect is in view, so it is seen (\$id.pending counts it). play: a burst plays out on time, unpainted (an effect tied to a moment elsewhere on the page). (wait, play) | `wait` |
| `on` | A nested <particles> only: the parent particle's event it answers. (death, birth, trail, edge) |  |
| `opacity` | Opacity 0–1 (1 - life fades it out). | `1` |
| `preset` | A named bundle of these attributes; any attribute here overrides it. (rain, snow, stars, twinkle, confetti, sparkles, bubbles, embers) |  |
| `rate` | Particles per second. On a trail sub-emitter: per parent, per second. |  |
| `rotation` | Degrees (age * 360 spins it). A line also points along its velocity. |  |
| `seed` | The same seed, the same particles on every run. |  |
| `shape` | circle, square, ring, star, glow (a soft dot), line, icon:<name> (with the modifiers <icon> takes: icon:favorite fill, icon:star outlined 700), image:<src>. | `circle` |
| `size` | Size in px (a line: its length). | `4` |
| `spawn` | Where particles are born: box (default), top, bottom, left, right, center, touch, point(x, y), line(x1, y1, x2, y2), rect(x, y, w, h); on a sub-emitter, parent (the default). |  |
| `vx` | Velocity px/s: of per-particle constants, the starting speed; of t, x, y …, a velocity field read every frame. |  |
| `vy` | Velocity px/s, as vx. |  |
| `x` | Parametric position: x as a formula (w/2 + cos(t + i) * 80). Without it, velocity moves the particle. |  |
| `y` | Parametric position, as x. |  |

## Commands

| Name | What it does |
|---|---|
| `burst` | Release N particles now (burst=, else 60). With reduced motion: one still frame early in their life, gone when their lifetime is up. |
| `clear` | Remove every particle at once. |
| `start` | Emit (after autostart="false" or #id.stop). |
| `stop` | Stop emitting; live particles carry on. Once none is left the layer asks for no frames until #id.start or a burst. |

## Readings

| Name | What it does |
|---|---|
| `alive` | Particles alive now. |
| `density` | The density in force (1 is full). |
| `over_budget` | Whether the frame budget made it thin out. |
| `pending` | Spawns waiting for a frame. |

Any tag also takes gestures: `@on.tap`, `@on.longpress`, `@on.doubletap` and `@on.swipeleft` (and right, up and down). `@click` runs on a tap too.

## Guides and recipes that use it

- [Animations and effects](https://hypeapps.dev/docs/guides/animations.md)

## Related tags

- [`<stack>`](https://hypeapps.dev/docs/reference/stack.md): Layers its children on top of each other, each drawn over the last, like a caption over a photo.
- [`<ad>`](https://hypeapps.dev/docs/reference/ad.md): An ad slot in the page, filled with a banner from AdMob in a built app.
- [`<avatar>`](https://hypeapps.dev/docs/reference/avatar.md): A round avatar from a photo, initials or an icon, in any size and color.
- [`<badge>`](https://hypeapps.dev/docs/reference/badge.md): A small count or dot pinned to the corner of an icon or any other element.
- [`<canvas-tool>`](https://hypeapps.dev/docs/reference/canvas-tool.md): A drawing tool written in HAM and loaded into a draw pad as a plugin: touch handlers, state and options.
- [`<caption>`](https://hypeapps.dev/docs/reference/caption.md): A table caption, shown as a label above the table.
- [`<carousel>`](https://hypeapps.dev/docs/reference/carousel.md): Swipeable pages side by side, one at a time, with dots below that show which page is on screen.
- [`<chart>`](https://hypeapps.dev/docs/reference/chart.md): A line, area, bar or sparkline chart drawn from a list of values; a tap shows a point's value.

All tags: https://hypeapps.dev/docs/reference.md · The full reference: https://hypeapps.dev/llms.txt
