# beam

A light beam that runs around the rounded border of a feature card, an input field or a highlight box.

A bright head of the first color with a soft trail of length px that turns into the second color and fades, running clockwise along the element’s edge at speed px per second and following its border radius, with a glow around the line. The pulse motion sends two beams from the top middle both ways round to meet at the bottom, then rests; hover runs the beam only while the element is hovered or has focus inside. The element stays DOM; the light draws over its edge.

Module `blocks`, category Blocks and cards. Import `@dioramajs/blocks/beam`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/blocks/src/beam.ts)

A dark feature card announcing realtime sync, with an orange-to-violet beam running around its rounded border.

```html title="index.html"
<div class="features">
  <article class="feature" data-dio="beam">
    <p class="label">New in 4.2</p>
    <h3>Realtime sync</h3>
    <p>Every edit lands on every device in under 100 ms, even on a train with one bar of signal.</p>
    <a href="/features">Read the changelog</a>
  </article>
</div>
```

## Usage

Put it on: any element with a box: a card, a form field wrapper, a pricing plan, a callout.

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

```html
<article class="feature" data-dio="beam"><h3>Realtime sync</h3><p>Every change lands on every device in under 100 ms.</p></article>
```

In page transitions: The beam fades with the page as it leaves.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `motion` (rebuilds) | `data-dio-motion` | `'loop' \| 'pulse' \| 'hover'` | `'loop'` | loop runs all the time; pulse sweeps from the top now and then; hover on hover or focus. |
| `color` | `data-dio-color` | `color` | `'#ffaa40'` | Color of the beam’s head, any CSS color. |
| `color2` | `data-dio-color2` | `color` | `'#9c40ff'` | Color the trail turns into toward its end, any CSS color. |
| `length` | `data-dio-length` | `number` 20 to 600 px | `240` | Length of the beam with its trail along the border. |
| `speed` | `data-dio-speed` | `number` 0 to 1000 px/s | `200` | Speed along the border; 0 stops the beam where it is. |
| `thickness` | `data-dio-thickness` | `number` 0.5 to 8 px | `2` | Thickness of the line. |
| `glow` | `data-dio-glow` | `number` 0 to 2 | `0.8` | Strength and reach of the soft light around the line; 0 draws the line alone. |
| `fps` | `data-dio-fps` | `number` 0 to 120 | `60` | Most frames a second while the beam runs; 0 holds it still. At most low 30, medium 45. |

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

### Variants

- `motion`: `loop`, `pulse`, `hover`
  - `loop` runs all the time.
  - `pulse` sweeps from the top now and then.
  - `hover` on hover or focus.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`motion`](/docs/api/inputs#motion), [`opacity`](/docs/api/inputs#opacity), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`size`](/docs/api/inputs#size), [`width`](/docs/api/inputs#input-width). Draws at a steady rate while it is on screen and stops when it leaves. At most fps a second while on screen for loop and pulse; for hover only while hovered, focused or fading out, none at rest. 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. Static: a faint still border in the two colors instead of the moving beam; with hover it shows while hovered or focused.

Runs on every device. A tap runs the hover beam while the finger is down; a focused field keeps it running.

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

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

## Cost and quality

Loads 2.3 KB the first time a page uses it. GPU: One draw of a thin frame around the box; the inside of the element is never shaded. Memory: Eight vertices.

- low: At most 30 frames a second.
- medium: At most 45 frames a second.

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

## Recipes

### A field that lights up while you type

With `motion="hover"` the beam runs while the pointer is over the element or focus is inside it, so a wrapped email field keeps its beam while someone types. Cool colors suit a form; a shorter `length` keeps the beam tidy on a short pill.

A newsletter form on a navy page whose email field lights up with a blue beam on hover and focus.

```html title="index.html"
<form class="signup" action="#signup">
  <h3>Get the launch notes</h3>
  <label class="field" data-dio="beam" data-dio-motion="hover" data-dio-color="#38bdf8" data-dio-color2="#6366f1" data-dio-length="120">
    <input type="email" name="email" placeholder="you@company.com" aria-label="Email address" />
  </label>
  <button type="submit">Subscribe</button>
</form>
```

## Notes

The element stays DOM: the beam draws over its edge on the canvas, as a thin frame around the box, so the inside of a large card costs nothing. It follows the largest of the element’s corner radii, so give all four corners the same `border-radius`. The line sits inside the edge, where a 1 or 2 px CSS border is, and the glow spreads to both sides of it.

`motion="loop"` and `motion="pulse"` draw at most `fps` frames a second while the element is on screen and nothing while it is off screen or the tab is hidden; `fps="0"` holds the beam where it is. With `motion="hover"` nothing is drawn at rest.

Under reduced motion the beam stands still as a faint border in its two colors.

`motion` rebuilds the effect when it changes; the other params change live.

## Related

- [glow](/docs/effects/glow.md): A spotlight that follows the pointer over a grid of cards and lights up their borders, as on SaaS and developer tool sites.
- [shine](/docs/effects/shine.md): A glint that sweeps across a button, a card or an image on hover, on a timer or as it comes into view.
- [beat](/docs/effects/beat.md): A cover, logo, card or play button that pulses with the music of a page player: it scales, shakes and glows, or sends out rings, on the beat.
- [coin](/docs/effects/coin.md): A coin, medal or token struck from a logo or a photo: it turns, catches the light and flips over.
- [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.
- [emboss](/docs/effects/emboss.md): Letters pressed into or raised out of paper, leather, brushed metal, stone or plaster, lit by a light that follows the pointer.
- [emoji](/docs/effects/emoji.md): Emoji or small pictures that float up from a like button, burst out of a success state or rain over a section.
- [keycaps](/docs/effects/keycaps.md): Each letter sits on a 3D mechanical keycap that presses down as if the word were typed, with a click under the pointer.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
