Skip to Content
zjkm-ui
Components

Pixel Mosaic

An image loader that resolves from big pixels to sharp.

Demo photo
Props
24
900ms
<PixelMosaic placeholder={photo.blurDataURL}>
  <Image src={photo} alt="…" />
</PixelMosaic>

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/pixel-mosaic-tw.json
import { PixelMosaic } from "@/components/pixel-mosaic"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

Pixel Mosaic wraps an <img> or next/image. While the photo loads it shows a shimmering mosaic of the placeholder (or a flat color), then sharpens it into the photo. Your image keeps its alt, size and loading behaviour.

import Image from "next/image";
import { PixelMosaic } from "@/components/pixel-mosaic";
import photo from "./photo.jpg";

export function Hero() {
  return (
    <PixelMosaic placeholder={photo.blurDataURL}>
      <Image src={photo} alt="Harbour at dusk" />
    </PixelMosaic>
  );
}

Installed the CSS variant? Import from @/components/pixel-mosaic-plain instead.

Props

PropTypeDefaultDescription
childrenReactNodeThe element that contains your <img> or next/image.
placeholderstringTiny image URL or data URL drawn as the loading mosaic.
colorstring"#a1a1aa"Mosaic colour when there is no placeholder.
cellSizenumber24Starting cell size in CSS pixels.
durationnumber900Length of the reveal in milliseconds.
classNamestringClasses for the wrapper.

On this page