Skip to content
Logic2BUI

Search docs

Search components and documentation

New
Menu

Aspect Ratio

Displays content within a desired ratio.

16 / 9

Installation

npx logic2b@next add aspect-ratio

Usage

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>

API reference

Generated from the public TypeScript exports in src/ui/aspect-ratio.tsx.

View JSON

AspectRatio

Component
Props: React.ComponentProps<typeof AspectRatioPrimitive.Root>

Accessibility contract

Machine-readable behavior and consumer responsibilities for aspect-ratio.

View JSON
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.