Aspect Ratio

Keeps its content at a fixed width-to-height ratio, such as 16 / 9 for a video.

16 / 9

Usage

Code
import { AspectRatio } from '@leverui/components';

export function AspectRatioUsage() {
  return (
    <AspectRatio ratio={16 / 9}>
      <iframe title="Product tour" src="/embeds/product-tour.html" allowfullscreen />
    </AspectRatio>
  );
}

Examples

Image

An image in a 4 / 3 frame.

Mountain landscape

Video

A video in a square frame. ratio overrides the video's own shape.

Map

A map in a 16 / 9 frame.

Responsive

Square on small screens, 16 / 9 from the md breakpoint up.

Box

Guide

Aspect Ratio Token

CSS variables for common ratios: square, landscape, portrait, wide, ultrawide, and golden. Use them with aspect-ratio in your own CSS. The ratio prop takes numbers, not these variables.

Code
.square-preview {
  aspect-ratio: var(--leverui-aspect-ratios-square);
}

Props

PropDefaultTypeDescription
ratio4 / 3Positive number or responsive object/array of numbersWidth divided by height.
asdivNative HTML tagHTML tag to render.
asChild—Render callbackRender your own element as the frame. Keeps the layout props.
unstyledfalseBooleanTurn off the ratio layout styles.

Needs one child element, stretched to fill the frame. Images and videos are cropped to fit. Give each image alt text and each iframe a title.

Restyle with class, style, and the public CSS variables. No css prop.