Aspect Ratio

Keeps content at a set ratio and animates ratio changes.

Installation

pnpm dlx shadcn@latest add @paneui/aspect-ratio

Usage

Composition

Examples

Ratios

With Image

Radius

Without Animation

Motion

Ratio changes run as a motion layout animation with a bounce-free spring. With reduced motion the frame jumps straight to its new shape.

API Reference

AspectRatio

A full-width frame locked to a ratio, with a muted well background. Also accepts every prop of motion.div.

ratio= 1
number
Width divided by height, e.g. 16 / 9. Invalid values fall back to 1.
animated= true
boolean
Animate ratio changes. Reduced motion always skips the movement.
radius= 20
number
Corner radius in px.
contentClassName
string
Classes for the absolutely positioned content layer.
PropTypeDefaultDescription
rationumber1Width divided by height, e.g. 16 / 9. Invalid values fall back to 1.
animatedbooleantrueAnimate ratio changes. Reduced motion always skips the movement.
radiusnumber20Corner radius in px.
contentClassNamestring—Classes for the absolutely positioned content layer.

AspectRatioImage

Cover-cropped image for AspectRatio, sized from its real width and height. Must be used inside it. Also accepts every prop of motion.img.

alt*
string
Alternative text.
width*
number
Intrinsic width in px.
height*
number
Intrinsic height in px.
draggable= false
boolean
Native image dragging.
PropTypeDefaultDescription
alt*string—Alternative text.
width*number—Intrinsic width in px.
height*number—Intrinsic height in px.
draggablebooleanfalseNative image dragging.