Halftone Background - React Component | Kokonut UI
Halftone Background
Any image, or a lit sphere, printed as a halftone dot screen, with a loupe that looks closer under the cursor, built with React and canvas.
Installation
Halftone Background is a free, open-source React component in the Kokonut UI Backgrounds collection. Add it with the shadcn CLI, which copies the source into components/kokonutui/halftone-background.tsx, so the code is yours to change.
npx shadcn@latest add @kokonutui/halftone-background
Usage
import HalftoneBackground from "@/components/kokonutui/halftone-background";
export default function Example() {
return <HalftoneBackground />;
}
Props
className:string– Extra classes for the root element.children:ReactNode– Content shown over the dots. Passnullfor a bare background.src:string– An image to print as dots. It must be same-origin or served with CORS headers. Without one, a lit sphere is drawn.cell:numberDefault9– Distance between dots, in px.angle:numberDefault45– Screen angle in degrees; 45 is the classic print angle.loupe:booleanDefaulttrue– Show a loupe under the cursor that prints at twice the resolution.
Dependencies
| Needs | Version | Comes from |
|---|---|---|
cn from lib/utils.ts |
shadcn init | |
| React | 19 |
Your app |
| Tailwind CSS | 4 |
Your app |
No provider, font or global CSS to set up: the file works as soon as it lands.