Aspect Ratio

Displays content within a desired width-to-height ratio.

Features

  • Any ratio
  • Any content
  • No layout shift
  • Style passthrough
  • Headless

Installation

npm install @ariaui/aspect-ratio

Examples

Each playground fixes a different ratio (width ÷ height). Swap the inner node for video, iframe, or custom UI — the box keeps the proportion.

16 : 9

Common video and hero ratio. Pass ratio="16 / 9".

Preview

No preview output yet.

live.tsxReady

21 : 9

Ultra-wide framing for banners and film-style layouts.

Preview

No preview output yet.

live.tsxReady

4 : 3

Classic photo and slide ratio; preview width matches the other demos so the box shape reflects the ratio.

Preview

No preview output yet.

live.tsxReady

1 : 1

Square media tiles and avatars.

Preview

No preview output yet.

live.tsxReady

9 : 16

Vertical video and mobile-first previews.

Preview

No preview output yet.

live.tsxReady

Anatomy

tsx
import * as AspectRatio from "@ariaui/aspect-ratio";

export default function Example() {
  return <AspectRatio.Root />;
}

API Reference

Root

Constrains its children to a fixed width-to-height ratio using a private padding-bottom wrapper. Public props and refs apply to the absolutely-positioned fill element.

PropTypeDefault
ratio
number | string1
asChild
booleanfalse

Accessibility

The Aspect Ratio component has no ARIA role, keyboard behavior, or focus management of its own. Accessibility responsibility lies entirely with the content placed inside it.

Content requirements

  • <img> children must have a descriptive alt attribute.
  • <video> children should carry a title or aria-label.
  • <iframe> children should carry a title.

The outer and inner <div> elements carry no semantic role and are transparent to assistive technology.

Previous
Alert Dialog
Next
Avatar