nanosplash@4.1.2 · live on this page

The tiny loading screen for web artisans.

Every demo below runs the real library — the same ~2 kB gzipped bundle that ships from npm. Two functions, zero dependencies, full control.

2.1 kB gzipped 2 functions 0 dependencies 100% test coverage
show(label?) · hide(id?)

Show it, hide it

A splash over the whole page covers the viewport — nothing beneath it moves, and neither does your scroll position. show() returns a monotonic nsId you can hand back to hide(id). These demos hide themselves after two seconds so you get the page back.

const id = ns.show('Brewing coffee') // → nsId
ns.hide(id)  // or ns.hide() for oldest, ns.hide('*') for all
show(label, inside)

Scoped to any container

Pass an element, a CSS selector, or a ref as the second argument. A container that already holds a splash recycles it — reload a widget twice and the label updates instead of stacking a duplicate.

Revenue

last 7 days

Orders

latest 5

Activity

team feed
ns.show('Crunching numbers', '#w-revenue')
ns.show('Almost there', '#w-revenue') // recycled — text updates, no duplicate
show([label, job])

Labeled jobs

Hand show() a [label, job] pair and it runs the work under the splash, auto-hiding when it settles. An array of pairs runs sequentially under one splash — the label updates per step, and results come back as a typed tuple. Sequences are fail-fast; rejections propagate after the splash hides.

jobs run in here
const [user, posts, ok] = await ns.show([
  ['Loading user',  () => fetchUser()],
  ['Loading posts', () => fetchPosts()],
  ['Verifying',     () => verify()],
], '#stage-jobs') // typed tuple, in order
useNs({ showDelay, minDuration })

Anti-flicker timing

Two sins of loading screens: the flash of spinner on a fast operation, and the sub-100 ms blink. showDelay keeps the splash invisible for operations that finish quickly; minDuration holds it long enough to register. Run the same task through both instances and watch the right one behave.

useNs() — no timing
flickers on fast tasks
useNs({ showDelay: 250, minDuration: 600 })
stays calm
const ns = useNs({ showDelay: 250, minDuration: 600 })
// <250 ms task → splash never becomes visible
// visible splash → held ≥600 ms, no blink
--ns-* custom properties

Theming

Every visual knob is a public CSS custom property with defaults declared on :where(:root) — zero specificity, so your overrides always win. Adjust these while the splash is showing; changes apply live.

your theme, live
/* your stylesheet */
:root {
  --ns-bg: #0b151bcc;
  --ns-color: #3bc6ef;
  --ns-blur: blur(8px);
}
role="status" · aria-live · aria-busy

Accessible by default

The splash is a proper live region — no configuration required. Press the button and the chips below light up as each attribute is verified on the live DOM element, not hard-coded.

inspection target
role="status" aria-live="polite" aria-busy="true" on host aria-hidden spinner

The spinner animation also respects prefers-reduced-motion — with it enabled, the dash animation is replaced by a slow, steady rotation.