Aspect Ratio
Displays content within a desired ratio.
Loading example…
Installation
bunx --bun shadcn@latest add @sui/aspect-ratioInstall with the shadcn CLI or use the shared @workspace/ui package. Follow the installation guide to configure the registry, load styles, and choose import aliases.
Usage
import { AspectRatio } from "@workspace/ui/components/aspect-ratio"<AspectRatio ratio={16 / 9}>
<Image src="..." alt="Image" className="rounded-md object-cover" />
</AspectRatio>Square
A square aspect ratio component using the ratio={1 / 1} prop. This is useful for displaying images in a square format.
Loading example…
Portrait
A portrait aspect ratio component using the ratio={9 / 16} prop. This is useful for displaying images in a portrait format.
Loading example…
RTL
To enable RTL support in shadcn/ui, see the RTL configuration guide.
Loading example…
API Reference
AspectRatio
The AspectRatio component displays content within a desired ratio.
| Prop | Type | Default | Required |
|---|---|---|---|
ratio | number | - | Yes |
className | string | - | No |
For more information, see the Base UI documentation.