---
title: Aspect Ratio
description: Keep media and other content at a consistent ratio.
group: Components
order: 13
---

Give images, video, and placeholders a predictable frame with a single `ratio` prop.

```tsx
import { AspectRatio } from "@/components/ui/aspect-ratio"

export function Example() {
  return (
    <AspectRatio ratio={1} className="w-44 rounded-md bg-surface-hover" />
  )
}
```

## Installation

```bash
npx @arctis-sh/@arctis-sh/ui@latest add aspect-ratio
```

## Usage

```tsx
import { AspectRatio } from "@/components/ui/aspect-ratio"
```

```tsx
<AspectRatio ratio={16 / 9} className="h-44 w-auto rounded-md bg-surface-hover" />
```

## Square

Use `ratio={1}` for a square frame.

```tsx
import { AspectRatio } from "@/components/ui/aspect-ratio"

export function Example() {
  return (
    <AspectRatio ratio={1} className="w-44 rounded-md bg-surface-hover" />
  )
}
```

## Portrait

Use `ratio={9 / 16}` for a tall portrait frame.

```tsx
import { AspectRatio } from "@/components/ui/aspect-ratio"

export function Example() {
  return (
    <AspectRatio ratio={9 / 16} className="w-44 rounded-md bg-surface-hover" />
  )
}
```

## Rectangle

Use `ratio={16 / 9}` for a wide landscape frame.

```tsx
import { AspectRatio } from "@/components/ui/aspect-ratio"

export function Example() {
  return (
    <AspectRatio
      ratio={16 / 9}
      className="h-44 w-auto rounded-md bg-surface-hover"
    />
  )
}
```

## API Reference

### AspectRatio

| Prop | Type | Default |
| --- | --- | --- |
| ratio | number | 1 |
| className | string | — |

```tsx
<AspectRatio ratio={16 / 9}>
  <img src="..." alt="..." className="size-full object-cover" />
</AspectRatio>
```

## Source

```tsx
import type { HTMLAttributes, ReactNode } from "react";
import { cn } from "@/lib/utils";

type AspectRatioProps = HTMLAttributes<HTMLDivElement> & {
  ratio?: number;
  children?: ReactNode;
};

export function AspectRatio({
  ratio = 1,
  className,
  children,
  style,
  ...props
}: AspectRatioProps) {
  return (
    <div
      className={cn("relative overflow-hidden", className)}
      style={{ aspectRatio: ratio, ...style }}
      {...props}
    >
      {children}
    </div>
  );
}
```
