Docs
Aspect Ratio
Aspect Ratio
Displays content within a desired ratio.
<script lang="ts">
import { AspectRatio } from "$lib/components/ui/aspect-ratio/index.js";
</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="h-full w-full rounded-md object-cover"
/>
</AspectRatio>
<script lang="ts">
import { AspectRatio } from "$lib/components/ui/aspect-ratio/index.js";
</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="h-full w-full rounded-md object-cover"
/>
</AspectRatio>
Installation
npx shadcn-svelte@next add aspect-ratio
Install bits-ui
:
npm i bits-ui -D
Copy and paste the component source files linked at the top of this page into your project.
Usage
<script lang="ts">
import { AspectRatio } from "$lib/components/ui/aspect-ratio/index.js";
</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