Aspect Ratio

Keeps media at a fixed width-to-height ratio; rounded, clipped container by default.

About Aspect Ratio

Keeps media at a fixed width-to-height ratio; rounded, clipped container by default.

Aspect Ratio is a free primitive component for React, built on shadcn/ui and Tailwind CSS. It ships as 27 lines of TypeScript you own: every piece of copy is a prop with a sensible default, so you can drop it in and replace the content without touching the layout.

  • aspect ratio
  • media
  • image
  • video
  • layout

Installation

  1. Add the Chocolate UI registry to your components.json (see the installation guide).
  2. Run the shadcn CLI:
npx shadcn@latest add @chocolate/aspect-ratio

Dependencies installed automatically: radix-ui.

Uses: utils.

Usage

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

export default function Page() {
  return <AspectRatio />
}

FAQ