Aspect Ratio

Base UI

A stable frame for images and other media.

MacBook Pro on a workspace
ReadyResponsive

Usage

Package export
tsx
"use client";
import { AspectRatio } from "@jnpll/elements-ui/aspect-ratio";
export default function AspectRatioDemo() { return <AspectRatio ratio={16 / 9} className="w-full max-w-sm"><img src="/samples/workspace.webp" alt="MacBook Pro on a workspace" className="size-full rounded-md object-contain bg-white" /></AspectRatio>; }

Examples

Default composition
tsx
"use client";
import { AspectRatio } from "@jnpll/elements-ui/aspect-ratio";
export default function AspectRatioDemo() { return <AspectRatio ratio={16 / 9} className="w-full max-w-sm"><img src="/samples/workspace.webp" alt="MacBook Pro on a workspace" className="size-full rounded-md object-contain bg-white" /></AspectRatio>; }

API Reference

PropType / descriptionDefault
rationumber

Width divided by height.

1
classNamestring

Additional classes, merged with the component styles.

-

Composition & accessibility

Import the composition slots shown in the example. Keep labels and descriptions meaningful; interactive primitives provide keyboard and focus behavior. See the source for the complete typed API.