# clouds

A sky of soft layered clouds for the time of day, daylight, a sunset or a moonlit night, drifting in the wind and parting on scroll.

A sky gradient from the horizon up with up to three layers of clouds over it. Clouds shrink and thin out toward the horizon, so the sky has depth; each one is lit from the sun, bright on its sunny side, darker where it is thick and underneath, with a glowing edge where it is thin. The wind moves the layers sideways, nearer ones faster, and the scroll and the pointer shift them apart. The day style has a blue sky with white clouds and a pale sun high up, sunset an orange to violet sky with peach clouds and the sun low, night a dark blue sky with stars and clouds lit by the moon.

Module `backgrounds`, category Backgrounds. Import `@dioramajs/backgrounds/clouds`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/backgrounds/src/clouds.ts)

A flight card with a blue daytime sky of soft drifting clouds beside the route, times and price.

```html title="index.html"
<article class="cl-trip">
  <div class="cl-sky" aria-hidden="true" data-dio="clouds" data-dio-cover="0.45"></div>
  <div class="cl-info">
    <p class="cl-kicker">Direct flight, 2 h 55 min</p>
    <h2>Lisbon for the weekend</h2>
    <dl>
      <div><dt>Departs</dt><dd>Fri 18:40</dd></div>
      <div><dt>Returns</dt><dd>Sun 21:15</dd></div>
      <div><dt>From</dt><dd>€89</dd></div>
    </dl>
    <p>Cabin bag included. Seats by the window go first, so pick yours early.</p>
  </div>
</article>
```

## Usage

Put it on: an empty decorative element behind the content, such as an aria-hidden div filling a hero; its CSS background is the look without WebGL.

`start()` registers `clouds`, so the attribute alone puts it on an element.

```html
<header class="hero"><div class="hero-sky" aria-hidden="true" data-dio="clouds" data-dio-cover="0.4"></div><h1>Fly to Lisbon from 49 €</h1></header>
```

In page transitions: Fades with the page transition.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'day' \| 'sunset' \| 'night'` | `'day'` | day, a blue sky with white clouds, for travel, airline and kids’ sites; sunset, an orange and violet sky with peach clouds, for hotels, resorts and evening events; night, a dark sky with stars and moonlit clouds, for sleep, night events and dark themes. |
| `cover` | `data-dio-cover` | `number` 0 to 1 | `0.5` | How much of the sky the clouds cover; 0 a clear sky, 1 overcast. |
| `speed` | `data-dio-speed` | `number` 0 to 1 | `0.2` | Wind speed; 0 holds the clouds in place. |
| `scale` | `data-dio-scale` | `number` 0.3 to 3 | `1` | Size of the clouds. |
| `sun` | `data-dio-sun` | `number` 0 to 1 | `0.6` | Brightness of the sun or the moon, its glow and the light on cloud edges; 0 hides it. |
| `depth` | `data-dio-depth` | `number` 0 to 1 | `0.2` | How far the layers shift apart with the pointer; 0 ignores the pointer. |
| `scroll` | `data-dio-scroll` | `number` 0 to 1 | `0.3` | How far the layers move while the element crosses the viewport, nearer ones more; 0 keeps them. |
| `layers` (rebuilds) | `data-dio-layers` | `number` 1 to 3 | `3` | Layers of clouds, 1 to 3. At most low 1, medium 2. |
| `fps` | `data-dio-fps` | `number` 0 to 60 | `30` | Most frames a second the wind draws; 0 holds it still. At most low 15, medium 24. |
| `seed` (rebuilds) | `data-dio-seed` | `number` 1 to 100 | `1` | Shapes of the clouds. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `style`: `day`, `sunset`, `night`
  - `day` a blue sky with white clouds, for travel, airline and kids’ sites.
  - `sunset` an orange and violet sky with peach clouds, for hotels, resorts and evening events.
  - `night` a dark sky with stars and moonlit clouds, for sleep, night events and dark themes.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`hover`](/docs/api/inputs#hover), [`pointer`](/docs/api/inputs#pointer), [`progress`](/docs/api/inputs#progress), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`size`](/docs/api/inputs#size). Draws at a steady rate while it is on screen and stops when it leaves. Up to fps frames a second while on screen, none off screen or at fps 0; pointer and scroll draw at full rate. See [how a frame is decided](/docs/concepts/frames).

## Reduced motion and touch

With reduced motion it shows a still frame: motion inputs are zero and time stands still. A still sky: no wind, and neither the pointer nor scroll moves the clouds.

Runs on every device. The layers shift with a finger while it is on the screen; scrolling works as usual.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { clouds: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 2.1 KB the first time a page uses it. GPU: One pass over the element: four reads of a noise tile per layer and pixel. Memory: A 256 × 256 noise tile, 256 KB, shared by every clouds of the same seed.

- low: At most 15 frames a second and one layer of clouds.
- medium: At most 24 frames a second and two layers.

See [the quality plugin](/docs/effects/quality).

## Recipes

### A travel hero

Put the clouds on an empty `aria-hidden` element that fills the hero and start the app with `canvas: 'behind'`, so the heading sits over the sky. The element’s CSS background is what visitors see before the engine draws and without WebGL: a gradient in the colors of the style.

```html
<header class="hero">
  <div
    class="hero-sky"
    aria-hidden="true"
    data-dio="clouds"
    data-dio-cover="0.4"
  ></div>
  <h1>Fly to Lisbon from €49</h1>
  <a class="cta" href="/flights">Find a flight</a>
</header>
```

```css
.hero {
  position: relative;
  isolation: isolate;
  min-height: 80vh;
  color: #0b1f3a;
}
.hero-sky {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(0deg, #d6ecf8, #8ec4ec 45%, #3b7fd4);
}
```

```ts title="src/main.ts"
import { start } from '@dioramajs/diorama'

export const app = start({ canvas: 'behind' })
```

The CSS fallbacks of the other styles are `linear-gradient(0deg, #ffb26e, #ee7d8c 45%, #37397f)` for `sunset` and `linear-gradient(0deg, #1e2e54, #101b38 45%, #050a19)` for `night`.

### A night sky for a sleep app

`night` draws a dark sky with stars and clouds lit by the moon. A low `cover` and a slow `speed` keep it calm.

A dark blue night sky with stars, a small moon and a few moonlit clouds drifting slowly.

```html title="index.html"
<div class="cl-night" aria-hidden="true" data-dio="clouds" data-dio-style="night" data-dio-cover="0.35" data-dio-speed="0.12"></div>
```

### Clouds that part on scroll

`scroll` moves the layers apart as the section crosses the viewport, nearer ones more, so the sky has depth while visitors read. With `fps` at 0 the clouds move only with the scroll and draw nothing at rest.

```html
<section class="story">
  <div
    class="story-sky"
    aria-hidden="true"
    data-dio="clouds"
    data-dio-style="sunset"
    data-dio-scroll="0.8"
    data-dio-fps="0"
  ></div>
  <h2>Evenings on the terrace</h2>
</section>
```

## Readable text

- `day`: dark navy text such as `#0b1f3a` reads on both the sky and the clouds while `cover` stays at 0.5 or below. Over heavy cloud, put the text on a card.
- `sunset` and `night`: white text. Under `sunset`, keep the heading in the upper half, where the sky is darkest.
- `sun` at 0 removes the bright glow when it sits right behind the heading.

## Notes

The docs canvas sits above the page, so the examples here keep text beside the sky. Put text over the clouds with `canvas: 'behind'`, as in the first recipe.

The style chooses the whole palette: sky, cloud light and shade, and the sun or the moon. There are no color params yet.

It draws up to `fps` frames a second while it is on screen and none off screen; the pointer and scroll draw at full rate while they shift the layers. On the low tier it draws one layer of clouds at most 15 frames a second, on the medium tier two layers at 24.

`style`, `layers` and `seed` rebuild the effect when they change. Cover, speed, size, sun and parallax change live.

## Related

- [blobs](/docs/effects/blobs.md): Soft blobs of brand color drifting behind a hero: merging like a lava lamp, as blurred orbs or as glossy glass drops.
- [dots](/docs/effects/dots.md): A dot grid behind a hero or in a card that answers the pointer: dots near it grow, move aside or glow, then settle back.
- [gradient](/docs/effects/gradient.md): A living background of four soft color blobs or of aurora curtains, mixed in OKLab, without banding, with a light film grain.
- [grid](/docs/effects/grid.md): A grid floor in perspective running toward the viewer under a glowing horizon: neon synthwave, a blueprint or plain thin lines.
- [stars](/docs/effects/stars.md): A night sky of twinkling stars in depth layers that lean with the pointer and the scroll, with shooting stars and a warp flight.
- [waves](/docs/effects/waves.md): Topographic contour lines or flowing wave lines across a hero or footer, slowly changing and shifted by scroll.
- [assemble](/docs/effects/assemble.md): Thousands of lit particles fly out of the depth around the page and gather into a heading.
- [bend](/docs/effects/bend.md): Scroll speed bends the image like paper and splits its color channels.
- [Performance and quality](/docs/guides/performance.md)
- [Reduced motion](/docs/guides/reduced-motion.md)
