Aspect Ratio

Keeps content, such as an image, at a width-to-height ratio.

@cupertinoui/aspect-ratioRegistry JSON
Drift wallpaper, light

Installation

pnpm dlx shadcn@latest add @cupertinoui/aspect-ratio

The first install also adds the macOS theme. See Installation to set up the registry.

Usage

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

<AspectRatio ratio={16 / 10}>
  <img src="…" alt="…" className="size-full object-cover" />
</AspectRatio>

API Reference

Every part forwards the props of the underlying element. The props below are the ones CupertinoUI adds or changes.

AspectRatio

PropTypeDescription
rationumberWidth divided by height.
classNamestringExtra classes, merged with the component's own.