structyl

Aspect Ratio API

View component

The full prop reference for the Aspect Ratio component. Constrains content to a desired width / height ratio.

Import

tsx
import { AspectRatio } from '@structyl/styled';

Props

AspectRatio

A container component that maintains a specified aspect ratio for its contents, useful for responsive images and videos.

PropTypeDefault
ratio#number

The desired aspect ratio as width / height (e.g., 16/9 for widescreen, 1 for square). Defaults to 1.

1
asChild#boolean

If true, merges props onto child element instead of creating a wrapper div.

className#string

CSS class names to apply to the outer container. The styled version applies 'overflow-hidden rounded-md' by default.

style#React.CSSProperties

Inline styles merged with the container's default position: relative; width: 100% styles.

children#React.ReactNode

Content to render within the aspect-ratio container, typically an image or video element.

ref#React.Ref<HTMLDivElement>

Forwarded ref to the outer container div.

...rest#React.HTMLAttributes<HTMLDivElement>

All standard HTML div attributes are supported and forwarded to the container element.

Source code

If you didn't find what you need here, read the component implementation .

structyl — Accessible React Component Library