Aspect Ratio
Keep a box at a fixed proportion for images, video and embeds.
NewInstallation
Copy and paste the following code into your project.
Update the import paths to match your project structure.
Anatomy
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.