Components / Motion / Sparkles

Sparkles beta

Twinkling points of light scattered over a line of type — celebration, kept quiet.

Preview

TEN THOUSAND PARTS COPIED

Thank you for building with the mold.

<div class="k-spk" data-sparkles style="background:var(--k-zinc-950);color:var(--k-on-color);border-radius:14px;padding:34px 24px;text-align:center">
  <p style="font-size:11px;letter-spacing:.22em;font-weight:600;color:var(--k-zinc-400)">TEN THOUSAND PARTS COPIED</p>
  <p style="font-size:20px;font-weight:650;letter-spacing:-.02em;margin-top:9px">Thank you for building with the mold.</p>
</div>
/* KATA Sparkles — specks on their own clocks. */
.k-spk{position:relative;font-family:var(--k-font)}
.k-spk-i{position:absolute;border-radius:50%;background:currentColor;animation:k-spk-tw ease-in-out infinite alternate;pointer-events:none}
@keyframes k-spk-tw{from{opacity:.08;transform:scale(.55)}to{opacity:.95;transform:scale(1.15)}}
@media (prefers-reduced-motion:reduce){.k-spk-i{animation:none;opacity:.35}}
// KATA Sparkles — scatters the specks; each twinkles on its own clock.
document.querySelectorAll('[data-sparkles]').forEach(function (stage) {
  var N = 26;
  for (var i = 0; i < N; i++) {
    var s = document.createElement('span');
    s.className = 'k-spk-i';
    s.setAttribute('aria-hidden', 'true');
    var size = 2 + Math.random() * 3.4;
    s.style.width = size.toFixed(1) + 'px';
    s.style.height = size.toFixed(1) + 'px';
    s.style.left = (Math.random() * 98) + '%';
    s.style.top = (Math.random() * 92) + '%';
    s.style.animationDuration = (1.5 + Math.random() * 2.2).toFixed(2) + 's';
    s.style.animationDelay = (-Math.random() * 3).toFixed(2) + 's';
    stage.appendChild(s);
  }
});

Installation

CLI

node kata-ui.mjs add sparkles

Writes the part’s CSS and JS into your project. New to the CLI? See the CLI doc.

Manual

  1. Load tokens.css once, before any part.
  2. Copy the CSS tab into your stylesheet.
  3. Copy the HTML where it belongs. The part has a script — include it after the markup; it initializes itself.

Examples

On a light card

Your first deploy is live

Same specks, ink this time — the part takes the color of the room.

<div class="k-spk" data-sparkles style="border:1px solid var(--k-line);border-radius:14px;padding:26px 22px;text-align:center;color:var(--k-ink);background:var(--k-bg)">
  <p style="font-size:16.5px;font-weight:600">Your first deploy is live</p>
  <p style="font-size:12.5px;color:var(--k-ink-2);margin-top:5px">Same specks, ink this time — the part takes the color of the room.</p>
</div>

Usage

The script scatters about two dozen specks inside the stage and each twinkles on its own clock. Dots take the container’s color (currentColor), so the same part sparkles white over a hero and ink over a card. Keep the count low and the stage honest — sparkle is seasoning.

Accessibility

Decoration only, aria-hidden, and the twinkle stops under prefers-reduced-motion. The text it decorates must read complete with every speck removed — it will be, for some readers.

Anatomy

The public surface of this part, read from its own source. Class names are the API — the CSS tab above is the full contract.

.k-spkclass
.k-spk-iclass
data-sparklesdata hook

Related parts