skip to content
mpkcn

~/components/grain

Grain

A static film-grain overlay in two blend layers that stays visible on both the dark and the light theme, at no per-frame cost.

~/grain

A little texture on flat colors.

Static noise in two blend layers, so it reads on dark and light.

Installation

terminal
npx mpkcn add grain
deps:none beyond react· tested with react@19.3.0

Usage

Render it once, in your root layout. It covers the whole viewport as a fixed layer above the page and never catches clicks. It has no state, so it also works in a Server Component.

tsx
import { Grain } from "@/components/mpkcn/grain";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en" suppressHydrationWarning>
      <body>
        {children}
        <Grain />
      </body>
    </html>
  );
}

The noise is two layers of the same SVG tile: a screen layer that lifts dark pixels and a multiply layer that darkens light ones. A single overlay layer almost disappears on a near-black background; the pair stays visible on both themes. The tile is a background image, so it is drawn once and costs nothing per frame.

Examples

Inside a box

Pass contained to fill the nearest positioned parent instead of the viewport. Add isolate to the parent to blend only with what is inside it.

~/grain

A little texture on flat colors.

Static noise in two blend layers, so it reads on dark and light.

Stronger and coarser

tsx
<Grain intensity={2.5} size={220} />

Props

PropTypeDefaultDescription
containedbooleanfalseFill the nearest positioned parent instead of covering the whole viewport as a fixed overlay.
intensitynumber1Strength multiplier: 1 is the subtle default, 2 doubles it, 0 hides it.
sizenumber160Size of the repeating noise tile in px. Smaller is finer grain.
classNamestring—Extra classes for both noise layers, e.g. a different z-index (default z-[100]).

Accessibility

  • Both layers are aria-hidden and pointer-events: none: nothing to read, nothing to click through.
  • The grain is static, so there is nothing to turn off for reduced motion.
  • The default strength (4% and 2% on dark, 2% and 5% on light) is a texture, not a filter: text contrast stays the same. Keep intensity low over body text.
  • It is hidden when printing.