Aspect Ratio
Displays content within a desired aspect ratio, preserving proportions responsively across viewport sizes.
aspectRatio.tsx
Aspect Ratio component powered by Radix Primitives to maintain responsive dimensions.
ReactRadix UITailwindUI ComponentLayout
"use client";
import * as React from "react";
import * as AspectRatioPrimitive from "@radix-ui/react-aspect-ratio";
export interface AspectRatioProps
extends React.ComponentPropsWithoutRef<typeof AspectRatioPrimitive.Root> {
ratio?: number;
}
const AspectRatio = React.forwardRef<
React.ElementRef<typeof AspectRatioPrimitive.Root>,
AspectRatioProps
>(({ ratio = 16 / 9, ...props }, ref) => (
<AspectRatioPrimitive.Root ref={ref} ratio={ratio} {...props} />
));
AspectRatio.displayName = AspectRatioPrimitive.Root.displayName;
export { AspectRatio };
Default Ratio (16:9)
Standard widescreen aspect ratio suitable for video embeds and media cards.
ratio: number (default: 16 / 9)
Square Ratio (1:1)
Perfect 1:1 square ratio commonly used for avatars, product thumbnails, and grid galleries.
Ultrawide Ratio (21:9)
Cinematic ultrawide ratio ideal for page headers, hero banners, and cover images.
API Reference
Props — AspectRatio
Properties for configuring the AspectRatio component.
| Prop | Type | Default | Description |
|---|---|---|---|
| ratio | number | 16 / 9 | Desired width-to-height ratio (e.g. 16/9, 4/3, 1/1, 21/9). |
| className | string | — | Tailwind CSS classes for background styling, rounding, and overflow bounds. |