Bloom Logo

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)
16:9 Widescreen Landscape

Square Ratio (1:1)

Perfect 1:1 square ratio commonly used for avatars, product thumbnails, and grid galleries.

1:1 Square Portrait

Ultrawide Ratio (21:9)

Cinematic ultrawide ratio ideal for page headers, hero banners, and cover images.

21:9 Ultrawide Banner
API Reference

Props — AspectRatio

Properties for configuring the AspectRatio component.

PropTypeDefaultDescription
rationumber16 / 9Desired width-to-height ratio (e.g. 16/9, 4/3, 1/1, 21/9).
classNamestringTailwind CSS classes for background styling, rounding, and overflow bounds.