Aspect Ratio
Keep a box at a fixed proportion for images, video and embeds.
Installation
pnpm dlx nachui add aspect-ratioAnatomy
The box takes the full width of its parent and derives its height from
ratio through the CSS aspect-ratio property, so nothing jumps while the media loads. A direct img or video child fills the box with object-cover, and an iframe is stretched to cover it.Examples
Default
Ratios
Any number works:
1, 4 / 3, 3 / 4, 21 / 9.1 / 1
4 / 3
3 / 4
21 / 9
API Reference
AspectRatio
| Prop | Type | Default | Description |
|---|---|---|---|
ratio | number | 16 / 9 | Width divided by height |
as | React.ElementType | 'div' | Element to render |
className | string | - | Additional CSS classes, rounding goes here |
Found something to improve?
Notice a bug, typo, or missing detail on this page? Help us make the documentation better by opening a GitHub issue.