Aspect Ratio

No more squished cats. Keeps its content at a given width-to-height ratio.

Demo
A river running over stones below a forested mountain
16 / 9
A ladybird opening its wings on a flower bud
1 / 1
The gilded nave of a baroque church
3 / 4

Installation

Usage

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

<template>
  <AspectRatio :ratio="16 / 9" class="overflow-hidden rounded-lg bg-muted">
    <img src="/photo.jpg" alt="" class="size-full object-cover" />
  </AspectRatio>
</template>

Set ratio as width divided by height: 16 / 9, 1, 4 / 3.

API Reference

Data attributes

data-slotAttributesDescription
aspect-ratio—The inner box, where your attributes land.

Changelog

No changes yet.