vert-ui
Browse docs
All components

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.json

Preview

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

PropTypeDefaultDescription
rationumber1Width divided by height, e.g. 16 / 9 or 4 / 3.
fillbooleanfalseMakes direct children (img, video, overlays) absolutely fill the box.
asChildbooleanfalseRender the child element instead of a div.
classNamestring—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.