Aspect Ratio API
View componentThe full prop reference for the Aspect Ratio component. Constrains content to a desired width / height ratio.
Import
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.
| Prop | Type | Default |
|---|---|---|
| ratio# | numberThe desired aspect ratio as width / height (e.g., 16/9 for widescreen, 1 for square). Defaults to 1. | 1 |
| asChild# | booleanIf true, merges props onto child element instead of creating a wrapper div. | — |
| className# | stringCSS class names to apply to the outer container. The styled version applies 'overflow-hidden rounded-md' by default. | — |
| style# | React.CSSPropertiesInline styles merged with the container's default position: relative; width: 100% styles. | — |
| children# | React.ReactNodeContent 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 .