Aspect Ratio

Shadcn compatible aspect ratio wrapper that locks media to a ratio such as 16:9 or 1:1 using CSS aspect-ratio, with overflow clipped for images and video.

src/registry/ui/aspect-ratio.tsx/r/aspect-ratio.json

Installation#

bash
npx shadcn@latest add @minidev/aspect-ratio

MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/aspect-ratio.json

Usage#

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

export function Example() {
  return (
    <AspectRatio ratio={16/9} className="rounded-xl border border-border bg-sunken" />
  )
}

API reference#

AspectRatio props
PropTypeDefault
rationumber16 / 9

Also accepts every prop of <div>, passed through to the root element.

Examples#

All layout components