Docs
Aspect Ratio
Aspect Ratio
Displays content within a desired ratio.
Loading...
<script lang="ts">
import { AspectRatio } from "@/components/ui/aspect-ratio";
</script>
<AspectRatio ratio={16 / 9} class="bg-muted">
<img
src="https://images.unsplash.com/photo-1588345921523-c2dcdb7f1dcd?w=800&dpr=2&q=80"
alt="Gray by Drew Beamer"
class="rounded-md object-cover h-full w-full"
/>
</AspectRatio>
<script lang="ts">
import { AspectRatio } from "@/components/ui/aspect-ratio";
</script>
<AspectRatio ratio={16 / 9} class="bg-muted">
<img
src="https://images.unsplash.com/photo-1588345921523-c2dcdb7f1dcd?w=800&dpr=2&q=80"
alt="Gray by Drew Beamer"
class="rounded-md object-cover h-full w-full"
/>
</AspectRatio>
Installation
npx shadcn-svelte add aspect-ratio
Usage
<script lang="ts">
import { AspectRatio } from "$components/ui/aspect-ratio";
</script>
<div class="w-[450px]">
<AspectRatio ratio={16 / 9} class="bg-muted">
<img src="..." alt="..." class="rounded-md object-cover" />
</AspectRatio>
</div>
On This Page