Aspect Ratio

Displays content within a desired ratio.

Installation

pnpm add @ag/ui

Usage

import { AspectRatio } from "@ag/ui"
<AspectRatio ratio={16 / 9}>
  <Image src="..." alt="Image" className="rounded-md object-cover" />
</AspectRatio>

Examples

Square

A square aspect ratio component using the ratio={1 / 1} prop. This is useful for displaying images in a square format.

Portrait

A portrait aspect ratio component using the ratio={9 / 16} prop. This is useful for displaying images in a portrait format.

RTL

To enable RTL support in shadcn/ui, see the RTL configuration guide.

API Reference

AspectRatio

The AspectRatio component displays content within a desired ratio.

PropTypeDefaultRequired
rationumber-Yes
classNamestring-No

For more information, see the Radix UI documentation.