8.7k

Aspect Ratio

PreviousNext

Displays content within a desired ratio.

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

<template>
  <AspectRatio :ratio="16 / 9" class="bg-muted rounded-lg">
    <img
      src="https://images.unsplash.com/photo-1588345921523-c2dcdb7f1dcd?w=800&dpr=2&q=80"
      alt="Photo by Drew Beamer"
      fill
      class="h-full w-full rounded-lg object-cover dark:brightness-[0.2] dark:grayscale"
    >
  </AspectRatio>
</template>

Installation

pnpm dlx shadcn-vue@latest add aspect-ratio

Usage

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

<template>
  <AspectRatio :ratio="16 / 9">
    <img src="..." alt="Image" class="rounded-md object-cover">
  </AspectRatio>
</template>