structyl

Aspect Ratio

stable

Constrains content to a desired width / height ratio.

Basic usage

16:9

Examples

Portrait and square

Use different ratios for portrait (4/5) and square (1/1) crops.

4:5
1:1

Media cards

AspectRatio keeps image, video and preview tiles stable across responsive widths.

Workspace desk
4:3 preview area

Features

  • Any ratio.
  • Works with images or any node.

Installation

bash
pnpm dlx structyl add aspect-ratio

API Reference

AspectRatio

Constrains content to a width/height ratio.

PropTypeDefault
rationumber

The desired ratio, e.g. 16 / 9.

1
classNamestring

Additional Tailwind classes, merged with the component defaults.

Aspect Ratio | structyl