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.
In a row or a grid of columns, give each column that holds a box min-width: 0, as the previews above do. A flex or grid 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. A phone turned upright then leaves the columns wider than the screen. A grid already gives the columns it builds from cols a minimum of zero.
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 second 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.