Ratios
The same width, four ratios: 16:9, 4:3, 1:1 and 3:4, each a small print with a white border. Change the width of the container and each box keeps its shape.
A box that keeps its width-to-height ratio while its width changes. Exactly shadcn's; the hand-made part is what surrounds it: a photograph on a Polaroid, a print taped at its corners, a map pinned to the desk.
npx shadcn@latest add @wobko/aspect-ratioFirst time here? Add the registry to components.json first. How to install
The same width, four ratios: 16:9, 4:3, 1:1 and 3:4, each a small print with a white border. Change the width of the container and each box keeps its shape.
A square picture in a photo-stock Paper with the wide white border at the bottom and a line of handwriting. Two strips of washi hold it to the desk; the caption stays upright while the print lies a little crooked.
A 4:3 print with no border, held by four strips of masking tape laid across its corners. The tape is placed with className (absolute, a little outside, turned), like any element.
Thumbnails that stay 4:3 whatever the columns do, each with its caption underneath. Resize the window: the grid reflows and every picture keeps its shape.
The shadcn demo: a 16:9 box with an <img> inside it, `object-cover` so the picture fills the box and is cropped, never squashed. The same picture in a square shows what gets cut. Swap the data URI for your own photograph.
A Radix AspectRatio: a relatively positioned wrapper with padding-bottom set from the ratio, and an absolutely positioned inner div (which receives className, data-slot and your children). It draws nothing: put an img with h-full w-full object-cover in it, or any content, and frame it with Paper and Tape.
| Prop | Type | Default | Description |
|---|---|---|---|
| ratio | number | 1 | Width divided by height: 16 / 9, 4 / 3, 1. |
The files the CLI copies into your project.
Loading the source