Components
Aspect Ratio
Displays content within a desired ratio.
Installation
CLI
npx shadcn@latest add https://exawizards.com/exabase/design/registry/aspect-ratio.jsonManual
Copy and paste the following code into your project.
import { cn } from "@/lib/utils"
function AspectRatio({
ratio,
className,
...props
}: React.ComponentProps<"div"> & { ratio: number }) {
return (
<div
data-slot="aspect-ratio"
style={
{
"--ratio": ratio,
} as React.CSSProperties
}
className={cn("relative aspect-(--ratio)", className)}
{...props}
/>
)
}
export { AspectRatio }
Usage
import Image from "next/image"
import { AspectRatio } from "@/components/ui/aspect-ratio"<div className="w-[450px]">
<AspectRatio ratio={16 / 9}>
<Image src="..." alt="Image" className="rounded-md object-cover" />
</AspectRatio>
</div>API
AspectRatio
The AspectRatio component displays content within a desired ratio.
| Prop | Type | Default | Description |
|---|---|---|---|
ratio | number | - | The aspect ratio of the content. Required |