Aspect Ratio

New

Keep content at a fixed width-to-height ratio.

Preview ​

Installation ​

npx sigma-ui@latest add aspect-ratio

Usage ​

vue
<script setup lang="ts">
import { AspectRatio } from '@/components/ui/aspect-ratio';
</script>

<template>
  <AspectRatio :ratio="16 / 9">
    <img
      src="/photo.jpg"
      alt="Cover"
    >
  </AspectRatio>
</template>

ratio is width divided by height. 16 / 9 is a widescreen frame, and 1 is a square. The image or other content should fill the box.

Examples ​

16:9 ​

API Reference ​

AspectRatio ​

Props

PropType Default
ratio

The desired ratio. Eg: 16/9

number1
asChild

Change the default rendered element for the one passed as a child, merging their props and behavior.

Read our Composition guide for more details.

boolean-
as

The element or component this component should render as. Can be overwritten by asChild.

AsTag | Component"div"

Slots

SlotScope
default

Content that fills the ratio box. Receives the current ratio as a percentage.

{ aspect: number; }

Accessibility ​

The component only constrains layout. Give images an alt, and use an empty alt when the image is decorative.

KeyDescription
TabMoves focus to an interactive element inside the frame.
Edit this page on GitHub