Skip to content
Drivn logoDrivn

Aspect Ratio

Maintain consistent width-to-height ratios for images, videos, and embedded content.

Preview

16 / 9

Installation

npx drivn add aspect-ratio

Usage

1import { AspectRatio } from "@/components/ui/aspect-ratio"
2
3export default function Page() {
4 return (
5 <AspectRatio ratio="16/9">
6 <img
7 src="/hero.jpg"
8 alt="Hero"
9 className="w-full h-full object-cover"
10 />
11 </AspectRatio>
12 )
13}

Presets

16/9

16/9

4/3

4/3

1/1

1/1

With Image

Landscape

Custom Ratio

2.35 (Cinemascope)

API Reference

PropTypeDefaultDescription
ratio"16/9" | "4/3" | "1/1" | number"16/9"Aspect ratio as a string preset or custom number
classNamestringAdditional CSS classes to apply
childrenReact.ReactNodeContent to render inside the container