Componentsv2.189.1
Iconsv1.19.0
MCPv0.8.62
Tokensv0.34.3

AspectRatio

Github
Storybook

A utility component for constraining content to a fixed width-to-height ratio.

Importing

The component can be imported via:

import { AspectRatio } from '@customerio/pluma-components/react';

Usage

AspectRatio constrains its content to a fixed width-to-height ratio. It fills the width of its container and derives its height from the ratio prop, making it useful for responsive images, video embeds, maps, and placeholders.

The single child stretches to fill the container.

Loading editor

Ratio

The ratio prop accepts a number expressed as width / height. For example, 16 / 9 produces a widescreen container, 1 a square, and 3 / 4 a portrait. When omitted, it defaults to 1.

Loading editor

Media

Images and videos placed inside AspectRatio are stretched to fill the container and use object-fit: cover, so they crop rather than distort.

<AspectRatio ratio={16 / 9}>
  <img src="/photo.jpg" alt="" />
</AspectRatio>

Limiting the size

AspectRatio fills the width of its container, so constrain the container (for example with the style prop) to limit its overall size.

Loading editor

API

Default:1

The aspect ratio (width / height) of the container, e.g. 16 / 9 for widescreen or 1 for a square.

On this page