# Aspect Ratio

- **Section:** Components
- **URL:** https://refast.fastapicloud.dev/docs/components/aspect-ratio
- **Markdown:** https://refast.fastapicloud.dev/docs/components/aspect-ratio.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/components/utility/aspect_ratio.py
- **Live examples:** the widgets on this page need a browser; open the URL above to try them.
- **Applies to:** refast 0.12.2

Constrains its child to a fixed width-to-height ratio.
The child expands to fill the container while maintaining the ratio.

```python
from refast.components import AspectRatio

AspectRatio(ratio=16/9, children=[Image(src="...", alt="...")])
```

```python
AspectRatio(
    ratio=16/9,
    children=[
        Image(src="photo.jpg", alt="Photo", class_name="w-full h-full object-cover rounded-lg"),
    ]
)
```

## Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `ratio` | `float` | `1.0` | Width ÷ height ratio, e.g. `16/9`, `4/3`, `1.0` |
| `children` | `ChildrenType` | `None` | Content to constrain (typically an `Image`) |
| `class_name` | `str` | `""` | Extra Tailwind classes on the wrapper |

## Common Ratios

| Ratio | Float | Use case |
|-------|-------|----------|
| `16/9` | `1.777…` | Video thumbnails, hero images |
| `4/3` | `1.333…` | Classic TV, legacy photos |
| `1/1` | `1.0` | Profile pictures, tiles |
| `3/2` | `1.5` | DSLR photos |
| `21/9` | `2.333…` | Cinematic banner images |

## With an Image

```python
AspectRatio(
    ratio=16/9,
    class_name="rounded-lg overflow-hidden",
    children=[
        Image(
            src="https://example.com/photo.jpg",
            alt="Landscape photo",
            class_name="w-full h-full object-cover",
        )
    ]
)
```

## With a Video Embed

```python
AspectRatio(
    ratio=16/9,
    children=[
        Container(
            extra_props={"as": "iframe", "src": "https://www.youtube.com/embed/..."},
            class_name="w-full h-full",
        )
    ]
)
```

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
