Command Palette

Search for a command to run...

Aspect Ratio

Maintains a consistent width-to-height ratio for content.

Image

Installation

npm i @radix-ui/react-aspect-ratio

Usage

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import Image from "next/image" import { AspectRatio } from "@/components/ui/aspect-ratio" export function AspectRatioDemo() { return ( <div className="w-[450px]"> <AspectRatio ratio={16 / 9}> <Image src="/images/bg-1.jpg" alt="Image" className="rounded-md object-cover" fill /> </AspectRatio> </div> ) }

Props

ComponentPropsDescription
AspectRatioAspectRatioPrimitive.AspectRatioProps
ratio?: number
The component that maintains a consistent width-to-height ratio. Default ratio is 1/1.

Examples

Different Ratios

4:3 Ratio

4:3

Square (1:1) Ratio

1:1