Aspect Ratio
Locks its child to a fixed aspect ratio — for media, embeds and placeholders.
import { AspectRatio, Box } from "astralis-ui";
export function AspectRatioDemo() {
return (
<Box w="full" maxW="sm">
<AspectRatio ratio="wide" rounded="xl" overflow="hidden">
{/* The single child stretches to fill the frame; img/video get object-cover. */}
<img src="/placeholder.svg" alt="A starfield gradient" />
</AspectRatio>
</Box>
);
}Import#
import { AspectRatio } from "astralis-ui";Usage#
The single child is absolutely positioned to fill the frame; images and
videos are object-cover by default, so any source fills the ratio without
distortion. The frame clips overflow — pair with rounded for media cards.
Ratios#
Named ratios instead of magic numbers: square (1:1), landscape (4:3),
portrait (3:4), wide (16:9, the default), ultrawide (21:9), golden
(1.618:1), and auto.
square
square
landscape
landscape
portrait
portrait
wide
wide
golden
golden
import { AspectRatio, Center, Text, Grid, VStack } from "astralis-ui";
const ratios = ["square", "landscape", "portrait", "wide", "golden"] as const;
export function AspectRatioRatios() {
return (
<Grid columns={{ base: "2", md: "3" }} gap="4" w="full" maxW="md" alignItems="end">
{ratios.map((ratio) => (
<VStack key={ratio} gap="1" alignItems="stretch">
<Text as="span" size="xs" color="muted">{ratio}</Text>
<AspectRatio ratio={ratio} rounded="lg" overflow="hidden">
<Center bg="pink-subtle">
<Text size="xs" color="muted">{ratio}</Text>
</Center>
</AspectRatio>
</VStack>
))}
</Grid>
);
}Props#
Aspect Ratio extends Box and adds one prop:
| Prop | Type | Default | Description |
|---|---|---|---|
ratio | "auto" | "square" | "landscape" | "portrait" | "wide" | "ultrawide" | "golden" | "wide" | The frame's width-to-height ratio. |