---
title: "Aspect Ratio"
description: "A box that keeps a width-to-height ratio, so photos and video keep their shape and the page does not move while they load. It can animate to a new ratio."
url: https://gelatinui.com/components/aspect-ratio
markdown_url: https://gelatinui.com/components/aspect-ratio.md
access: free
install: "npx shadcn@latest add @gelatin-ui/aspect-ratio"
registry_item: https://gelatinui.com/r/aspect-ratio.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Aspect Ratio

> A box that keeps a width-to-height ratio, so photos and video keep their shape and the page does not move while they load. It can animate to a new ratio.

Page: https://gelatinui.com/components/aspect-ratio

## When to use it

Best for: Media that must keep its shape at every width, so the page does not move when it loads.

- Use it for an image, a video, a map, or a placeholder of fixed shape.
- Put the corners on the AspectRatio (`overflow-hidden rounded-*`), not on the image.
- Set `animate` to move to a new ratio on a spring.

## When not to use it

- For a picture with a load state and a fallback, use an [Image](https://gelatinui.com/components/image.md).
- For a surface with a header and a body, use a [Card](https://gelatinui.com/components/card.md).

## Notes for agents

- `ratio` is width over height: `16 / 9`.
- With no `animate`, the box runs no Motion code.
- `mode="crop"` keeps one frame and clips to the new ratio, with no layout.

## Anatomy

```text
AspectRatio
```

## API reference

### AspectRatio

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `ratio` | `number` |  | Width divided by height: `16 / 9`, `4 / 3`, `1`, `9 / 16`. |
| `animate` | `boolean` | false | Move to a new `ratio` on a spring. Default `false`: the box takes a new ratio at once, as a plain server-rendered `div`. |
| `mode` | `"crop" \| "page"` |  | With `animate`, how a new ratio shows. `page` (default): the box height moves, and layout runs each frame, so the content below flows with it. `crop`: the box keeps a fixed `frame`, and a `clip-path: inset` moves; no layout runs, so nothing below moves. |
| `frame` | `number` |  | With `animate` and `mode="crop"`: the ratio of the fixed frame. Default `1`: a square holds the contain box of every ratio. For a set of presets, use `clamp(1, smallest, largest)`: 4:3 to 21:9 gives `4 / 3`, and 16:9 with 9:16 gives `1`. |
| `transition` | `SpringConfig` |  | With `animate`: the spring (`SpringConfig`, physics or time form). Default `glide` (stiffness 700, damping 53, no overshoot, within 0.5% at about 280ms). A time spring runs as its physics twin, so it keeps its speed when a new ratio comes mid-move. |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| AspectRatio | `aspect-ratio` |  | `--aspect-ratio` |  |

## Usage

Set the ratio and put the media inside, so the box keeps its shape before the photo loads.

The sample also uses `image`, which this add does not write. One command adds them with this item:

```bash
npx shadcn@latest add @gelatin-ui/aspect-ratio @gelatin-ui/image
```

```tsx title="article-cover.tsx"
import { AspectRatio } from "@/components/ui/aspect-ratio";
import { Image } from "@/components/ui/image";

export function ArticleCover() {
  return (
    <AspectRatio ratio={16 / 9} className="overflow-hidden rounded-xl bg-muted">
      <Image
        src="/photos/lake-dock.webp"
        alt="A wooden dock on a calm lake at dawn"
        fill
        className="rounded-[inherit] object-cover"
      />
    </AspectRatio>
  );
}
```

## Compose

Rules:

- Group with a Frame (`group-in-frames`): Put related panels in one `Frame` with its header and footer outside the panels, and keep a plain `Card` for one block of content.
- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/aspect-ratio
```

It adds 8 registry items: 7 files, 1969 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `clsx`, `motion`, `tailwind-merge`.

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Image](https://gelatinui.com/components/image.md)
- [Card](https://gelatinui.com/components/card.md)
- [Skeleton](https://gelatinui.com/components/skeleton.md)

## Accessibility

It is a plain box with no role. The media inside it keeps its own name.

## Motion

| Part | Motion |
| --- | --- |
| Ratio | glide · spring · the height moves to the new ratio |
