16 / 9
Installation
npx logic2b@next add aspect-ratioUsage
import { AspectRatio } from "@/components/ui/aspect-ratio"
<AspectRatio ratio={16 / 9}>
<img src="..." alt="Image" className="rounded-md object-cover" />
</AspectRatio>
Usage notes
Also accepts any standard div props, which are forwarded to the wrapper.
Examples
Square
1 / 1
Portrait
3 / 4
Live playground
Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.
Generated JSX
<AspectRatio
ratio={1.7778}
className="flex items-center justify-center rounded-lg bg-muted text-sm text-muted-foreground"
>Responsive media</AspectRatio>Responsive media
API reference
Generated from the public TypeScript exports in src/ui/aspect-ratio.tsx.
AspectRatio
ComponentProps: React.ComponentProps<typeof AspectRatioPrimitive.Root>Accessibility contract
Machine-readable behavior and consumer responsibilities for aspect-ratio.
- Support
- Composition contract
- Pattern
- layout wrapper
- Radix Aspect Ratio
Built-in semantics
- Adds no semantic role and preserves the accessibility tree of its child content.
Consumer responsibilities
- Give contained images, videos and embeds their own accessible names or captions.