Skip to content

Aspect Ratio

Constrains its content to a fixed width-to-height ratio.

Installation

pnpm dlx shadcn@latest add @frontal-labs/aspect-ratio

Usage

import { AspectRatio } from "@/components/ui/aspect-ratio";
<AspectRatio ratio={16 / 9}>
  <img alt="" className="size-full object-cover" src="/photo.jpg" />
</AspectRatio>

API Reference

AspectRatio

A div that applies the given ratio through the CSS aspect-ratio property.

All other div props are forwarded.

Examples

Common Ratios

Constraining an Image