AspectRatio
Locks its child to a fixed aspect ratio — <img>, <video>, <iframe>, or any media wrapper that needs to keep its proportions while the canvas resizes.
Plain <div>; preserves whatever semantics the child carries. Provide alt text on image children (and a <title> on iframes) as you normally would.
Preview
tsx
import { AspectRatio, Center, Text } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<AspectRatio ratio={16 / 9} background="bg.subtle" borderRadius="md">
<Center>
<Text color="fg.muted">16 : 9</Text>
</Center>
</AspectRatio>
);
}
Common ratios
Section titled “Common ratios”Accepts a number or a string. 16/9, 4/3, 1/1, 21/9 are the most common video / photo / square / cinema ratios respectively.
Preview
tsx
import { AspectRatio, Center, Inline, Text } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<Inline gap="3" align="start" wrap>
{[
{ ratio: 16 / 9, label: '16 : 9' },
{ ratio: 4 / 3, label: '4 : 3' },
{ ratio: 1 / 1, label: '1 : 1' },
].map((r) => (
<AspectRatio
key={r.label}
ratio={r.ratio}
background="bg.subtle"
borderRadius="md"
width="160px"
>
<Center>
<Text color="fg.muted">{r.label}</Text>
</Center>
</AspectRatio>
))}
</Inline>
);
}
PropTypeDefaultDescription
className
string
—
Additional class names appended after Cynosure's base classes.
style
CSSProperties
—
Inline style overrides merged last.
children
ReactNode
—
Single child whose box is constrained to `ratio`.
ratio
string|number
1
Aspect ratio. Accepts a number (`16/9`) or a string (`"16 / 9"`).
paddingX
—
Horizontal padding (left + right). Overrides `padding` on the X axis.
paddingY
—
Vertical padding (top + bottom). Overrides `padding` on the Y axis.
height
—
Element height. Accepts a `SpaceToken`, `LengthValue`, or named alias.
minWidth
—
Minimum width — useful for preventing flex children from collapsing.
background
—
Background colour. Use a `ColorToken` like `"bg.surface"` for theme awareness.
borderColor
—
Border colour. Pair with `borderWidth` to make the border visible.
opacity
Responsive<number | `${number}`>
—
Opacity 0–1. Use sparingly — prefer surface tokens over translucency.
overflowX
—
Horizontal-axis overflow control. Overrides `overflow` for the X axis.
display
—
CSS `display` value. `"contents"` removes the element's box from layout.
position
—
CSS `position`. Pair with `top`/`right`/`bottom`/`left` for placement.
top
—
Top inset (when positioned). Accepts a `SpaceToken`, `"auto"`, `"0"`, or `LengthValue`.
flex
Responsive<"1" | "none" | "auto" | "initial" | (string & {})>
—
Shorthand: `1 | auto | none | initial | <css>`. Resolves to `flex` on the child.
asChild
boolean
—
When `true`, renders the primitive's single React child via `Slot`,
forwarding className/style/ref/event handlers onto it.
as
ElementType
"div"
Rendered intrinsic element or component.
ref
ForwardedRef<Element>
—
Recipes
Section titled “Recipes”- Wrap responsive media:
<AspectRatio ratio={16/9}><img src={src} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover' }} /></AspectRatio>. - Skeleton placeholders: nest a
<Skeleton />insideAspectRatioso the placeholder reserves the right space before the image loads. - Embed iframes (YouTube, Vimeo): set
ratio={16/9}and stretch the iframe to 100% height/width.