AspectRatio

Displays content within a desired ratio.

layout
image
container

Preview

16:9 Aspect Ratio

Code

TSX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { AspectRatio } from "@/components/ui/aspect-ratio"
import Image from "next/image"

export function AspectRatioDemo() {
  return (
    <div className="w-[400px]">
      <AspectRatio ratio={16 / 9}>
        <Image
          src="https://images.unsplash.com/photo-1588345921523-c2dcdb7f1dcd?w=800&dpr=2&q=80"
          alt="Image"
          fill
          className="rounded-md object-cover"
        />
      </AspectRatio>
    </div>
  )
}

API Reference

PropTypeDefaultDescription
rationumber1The desired aspect ratio for the content.