Skip to Content
zjkm-ui
Components

Halftone Image

An image rendered as halftone dots.

Demo photo
Props
8px
<HalftoneImage>
  <img src="/photo.jpg" alt="…" />
</HalftoneImage>

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/halftone-image.json
import { HalftoneImage } from "@/components/halftone-image"

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

Wrap an <img> or next/image, and it's redrawn as a grid of dots: the darker the area, the bigger the dot. Your image stays in place underneath, so its alt text and layout are untouched.

import { HalftoneImage } from "@/components/halftone-image";

export function Portrait() {
  return (
    <HalftoneImage cellSize={6}>
      <img src="/team/ada.jpg" alt="Ada, our founder" />
    </HalftoneImage>
  );
}

The effect reads the image's pixels, so an image from another site needs CORS headers and crossOrigin="anonymous". Without them, or without canvas support, the photo shows as-is.

It samples the whole image stretched to its box, so images cropped with object-fit: cover aren't matched exactly.

Props

PropTypeDefaultDescription
childrenReactNodeThe element that contains your <img>.
cellSizenumber8Pixels per dot.
colorstring"#111827"Dot colour.
backgroundstring"#ffffff"Paper colour behind the dots.
classNamestringClasses for the wrapper.

The halftone is static, so reduced motion changes nothing.

On this page