# Aspect Ratio

Displays content within a desired ratio.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available by appending `.md` to any URL or sending an `Accept: text/markdown` header. An agent skill is available at [/.well-known/agent-skills/site-skill.md](/.well-known/agent-skills/site-skill.md).





<ComponentPreview name="aspect-ratio-demo">
  <AspectRatioDemo />
</ComponentPreview>

## Installation [#installation]

<Tabs defaultValue="cli">
  <TabsList>
    <TabsTrigger value="cli">
      CLI
    </TabsTrigger>

    <TabsTrigger value="manual">
      Manual
    </TabsTrigger>
  </TabsList>

  <TabsContent value="cli">
    ```bash
    npx shadcn@latest add https://shadcn-cssinjs.com/r/aspect-ratio.json
    ```
  </TabsContent>

  <TabsContent value="manual">
    <Steps>
      <Step>
        Install the following dependencies:
      </Step>

      ```bash
      pnpm add @stylexjs/stylex
      ```

      <Step>
        Make sure [StyleX is configured](/docs/installation) and the design tokens are
        installed.
      </Step>

      <Step>
        Copy and paste the following code into your project.
      </Step>

      <ComponentSource name="aspect-ratio" title="aspect-ratio.tsx" />

      <Step>
        Update the import paths to match your project setup.
      </Step>
    </Steps>
  </TabsContent>
</Tabs>

## Usage [#usage]

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

```tsx
<AspectRatio ratio={16 / 9}>
  <img src="..." alt="Image" />
</AspectRatio>
```

## Examples [#examples]

### Square [#square]

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

<ComponentPreview name="aspect-ratio-square">
  <AspectRatioSquare />
</ComponentPreview>

### Portrait [#portrait]

Use a ratio below `1` for a portrait orientation.

<ComponentPreview name="aspect-ratio-portrait">
  <AspectRatioPortrait />
</ComponentPreview>



## RTL [#rtl]

To enable right-to-left support, see the [RTL guide](/docs/rtl).

<ComponentPreview name="aspect-ratio-rtl" direction="rtl">
  <AspectRatioRtl />
</ComponentPreview>

## API Reference [#api-reference]

### AspectRatio [#aspectratio]

The `AspectRatio` component displays content within a desired ratio.

| Prop        | Type     | Default | Required |
| ----------- | -------- | ------- | -------- |
| `ratio`     | `number` | `1`     | No       |
| `className` | `string` | -       | No       |
