Layout · component · 6K

Pixel scale

An integer zoom container: renders children at a fixed logical size and scales them by the largest whole number that fits, snapped so scale × devicePixelRatio stays a whole number of device pixels, with image-rendering: pixelated. Falls back to a smooth fit when even 1× does not fit.

fit="width" (default) only looks at the available width; fit="contain" also fits the height, so give the element a height. Also exports computePixelScale() and usePixelScale() for your own layouts.

Install

pnpm dlx shadcn@latest add @s7ui/pixel-scale

Example

This example also uses @s7ui/icons.

Drag the bottom-right corner of the frame to resize it. The 160×100 scene below only ever grows by whole steps.

Scene

Scale: 1×

Info

Files:
components/retro/pixel-scale.tsx
Uses:
—
Packages:
—