AspectRatio
Keeps a box in a proportion, 16/9 by default, whatever its width: images, video, maps and previews never jump while they load.
import { AspectRatio } from '@sypnia/ui/react'
On this page
Three proportions
16 / 9
4 / 3
1 / 1
Code
import { AspectRatio, Grid } from '@sypnia/ui/react';
const tile = { display: 'grid', placeItems: 'center', height: '100%', color: 'var(--fg-muted)', fontSize: 'var(--text-sm)' } as const;
export default function Media() {
return (
<Grid min="12rem" gap={4}>
<AspectRatio radius={3}><div style={tile}>16 / 9</div></AspectRatio>
<AspectRatio ratio="4 / 3" radius={3}><div style={tile}>4 / 3</div></AspectRatio>
<AspectRatio ratio={1} radius={3}><div style={tile}>1 / 1</div></AspectRatio>
</Grid>
);
} When to use it
Use it when
- Media whose size is known before it loads.
Do not use it when
- Text: it must be free to grow.
For everyone
- The media inside still needs its own text alternative.
Props
| AspectRatio | Type | Default |
|---|---|---|
className | string | |
fit | "cover" | "contain" | |
radius | 1 | 2 | 3 | 4 | |
ratio | string | number | 16 / 9 |