v0.3.1 StableFoundation ComponentReact 18 & 19Zero Runtime CSS

AspectRatio

Reserve responsive media space before content loads.

Interactive preview

Room for your next idea.

A responsive 16:9 canvas.

Usage

import { AspectRatio } from "@devvy-ui/react";

<AspectRatio ratio={16 / 9}><p>Reserved media canvas</p></AspectRatio>

API reference

Native HTML attributes, className, style and a forwarded ref are supported. Component-specific props:

PropTypeDefaultDescription
ratiopositive number16 / 9Width divided by height; invalid values fall back to a square.

Accessibility & behavior

Platform Behavior & Guidelines

A CSS padding fallback reserves the ratio without measurement JavaScript. Label images/video accessibly inside it. Content fills the canvas; choose a sensible ratio for text. Style the wrapper or inner content through public classes.

Source ownership

Run npx @devvy-ui/cli init once in your React project, then add the source:

npx @devvy-ui/cli add aspect-ratio

Make the source yours.

Start from the canonical implementation used by the package and registry. Change the code, keep the MIT notice, and build the behavior your project needs.

AspectRatio.tsxREACT / TSX

Edit your own copy. Downloaded source uses your changes; the component preview above uses the shipped version. Run the source installer first to include shared helpers.