Powered by Mintlify
Auto-generate your docs
Displays content within a desired aspect ratio.
npx shadcn@latest add aspect-ratio
import { AspectRatio } from "@/components/ui/aspect-ratio"
<AspectRatio ratio={16 / 9}> <img src="/photo.jpg" alt="Photo" /> </AspectRatio>
"use client" import { AspectRatio as AspectRatioPrimitive } from "radix-ui" function AspectRatio({ ...props }: React.ComponentProps<typeof AspectRatioPrimitive.Root>) { return <AspectRatioPrimitive.Root data-slot="aspect-ratio" {...props} /> } export { AspectRatio }
<div className="w-full max-w-md"> <AspectRatio ratio={16 / 9}> <img src="/placeholder.jpg" alt="Placeholder" className="rounded-md object-cover w-full h-full" /> </AspectRatio> </div>
<AspectRatio ratio={16 / 9}> <iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" className="w-full h-full" allowFullScreen /> </AspectRatio>
<AspectRatio ratio={1}> <img src="/square.jpg" alt="Square image" className="rounded-md object-cover w-full h-full" /> </AspectRatio>
ratio
number
1
className
string