Aspect Ratio
Locks a box to a width-to-height ratio so media reserves its space and the page never shifts while it loads.
Install
Install the component
Add the source straight into your project with the shadcn CLI — no package dependency to track.
npx shadcn@latest add https://vert-ui.dev/r/aspect-ratio.jsonPreview
Live preview
16 / 9
1 / 1
Usage
Examples
Responsive video
Media reserves its space
<AspectRatio ratio={16 / 9} fill className="rounded-lg">
<iframe src="…" title="…" />
</AspectRatio>Square avatar tile
1 / 1
<AspectRatio ratio={1} className="rounded-lg">
<img src="…" alt="…" className="size-full object-cover" />
</AspectRatio>Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| ratio | number | 1 | Width divided by height, e.g. 16 / 9 or 4 / 3. |
| fill | boolean | false | Makes direct children (img, video, overlays) absolutely fill the box. |
| asChild | boolean | false | Render the child element instead of a div. |
| className | string | — | Merged last, so you can add rounding or a background. |
Accessibility
Accessibility notes
- Reserving the ratio up front prevents cumulative layout shift, which is critical for users of screen magnifiers or switch access.
- The ratio is a presentation detail: keep meaningful media accessible — always provide alt text on images and a title on iframes.
- content is clipped (overflow-hidden), so never place focusable controls that could be cut off outside the visible area.