Aspect Ratio
A container that maintains a fixed aspect ratio. Useful for images, videos, maps, and embeds.
Basic Usage
Common Ratios
16:9 (default)
4:3
1:1 (square)
Portrait and Ultrawide
3:4 (portrait)
21:9 (ultrawide)
Props
| Prop | Type | Default | Description |
|---|---|---|---|
ratio |
string|number | '16/9' |
Aspect ratio value, e.g. "16/9", "4/3", "1/1", or 1.5 |
scope |
string|null | null |
Scoped personalization name |
The component renders as a <div> with overflow-hidden and position: relative. The native CSS aspect-ratio property handles the sizing. Children (images, videos, embeds) should use object-fit: cover and width: 100%; height: 100% to fill the container.
A grid gives the columns it builds from cols a minimum width of zero, as the second preview uses. In a row of your own, give each column that holds a box min-width: 0. A flex item does not shrink below the width of its content, and Safari and every other browser on iOS keep measuring that content at the width the column had before the window narrowed, so a phone turned upright leaves the columns wider than the screen.
Zero suits a column that holds only a box. A column with a caption under its box cannot shrink past the caption's longest word, so give it a floor that carries the caption, as the ultrawide column in the last preview does with min-width: 8rem. A floor set as a length does not depend on the image, so the narrowing problem above does not reach it.
Keyboard Interaction
This component is a layout wrapper. Keyboard interaction is delegated to its children.