A beam that finds your button.
It comes in from the top edge, passes through the primary button and lands on the surface below. It switches on a moment after the page has loaded.
The surface
The beam ends on this element's top edge. Use a screenshot, a mockup or a card.
Markup
Three things carry the wiring: data-beam on the section, a
.beam layer inside it, and data-beam-target on the button the beam passes
through. data-beam-surface is optional and says where it lands.
<section class="hero hero--center" data-beam data-beam-position="0.45">
<div class="beam" aria-hidden="true"></div>
<div class="container hero__content">
…
<a class="btn btn--primary" data-beam-target href="…">Request an invite</a>
<figure data-beam-surface>…</figure>
</div>
</section>
<script defer src="scripts/beam.f0ef30ca.js"></script> <!-- only on pages that use it -->
Attributes
Behaviour lives in attributes on the host.
| Attribute | Values | Default |
|---|---|---|
data-beam-position | 0 (left) … 1 (right), or random | 0.5 |
data-beam-delay | milliseconds after the page has loaded | 2000 |
random is rolled once per page load and kept off the extreme edges so the
beam stays in view. A value that isn't a number or random falls back to the centre.
Tokens
The look is a token, set in the client's theme.css.
| Token | Default | What it does |
|---|---|---|
--beam-color | var(--color-brand) | Any CSS colour |
--beam-intensity | 0.5 | 0 off · 1 bright · 2 blazing. Keep it low behind text. |
--beam-width | 0.2 | 0.2 a thin shaft … 1.6 a flood |
--beam-smoke | 0.7 | 0 clean light … 1 thick fog |
--beam-sparks | 0.6 | 0 none … 1.5 a lot |
--beam-pace | 1 | Speed of the drift toward the source; 0 freezes it |
--beam-fade | 1400ms | How long it takes to switch on |
Behaviour and limits
- Opt-in. A site whose pages have no
data-beamgets none of its CSS or JavaScript. The script is not part of the shared bundle. - Reduced motion. With
prefers-reduced-motionthe beam shows at once as a single still frame: no delay, no fade, no animation. - No WebGL2 or no JavaScript. A static cone of light is drawn by the CSS instead.
- Pauses when it is off screen or the tab is hidden, and renders at 60% resolution, which is fine for soft light.
- Dark themes. It adds light, so on a light background it will barely show.
- One per page. Only the first
[data-beam]is drawn. - Text. The beam sits behind the copy. If it crosses a paragraph, lower
--beam-intensityand check the contrast.
Tuning
The panel at the bottom right moves the tokens live on this page. Copy tokens
gives you the CSS for theme.css and the position attribute.