Aspect Ratio

Displays content within a desired ratio.

Installation

npx shadcn@latest add @fulldev/aspect-ratio

Usage

---
import { AspectRatio } from "@/components/ui/aspect-ratio"
---

<AspectRatio ratio={16 / 9}>
  <img src="/image.jpg" alt="Landscape" class="size-full object-cover" />
</AspectRatio>

Examples

Common Ratios

The ratio is width divided by height.

Image

The child controls its own crop. Use object-cover to fill the available area.

API Reference

PropTypeDefaultDescription
rationumberrequiredWidth divided by height, such as 16 / 9.

class, style, and other div attributes are forwarded. String and object style values are merged with the internal ratio variable.

See the GitHub source code for the component source.