SpecOS SpecOS icon Styleguide

Aspect Ratio

A component that maintains a consistent aspect ratio for its content, useful for images, videos, and other media.

Import

import AspectRatio from "$lib/components/AspectRatio.svelte";

Image Example

Abstract painting
<AspectRatio ratio={16/9} class_name="rounded-lg">
    <img
        src="/your-image.jpg"
        alt="Description"
        class="h-full w-full rounded-lg object-cover"
    />
</AspectRatio>

Color Example

1:1 Aspect Ratio

<AspectRatio ratio={1} class_name="rounded-lg w-full">
    <div class="h-full w-full rounded-lg bg-blue-500 flex items-center justify-center">
        <p class="text-sm text-white">1:1 Aspect Ratio</p>
    </div>
</AspectRatio>

Properties

ratio
Type
number
Default: 1
The aspect ratio to maintain (width/height). Example: 16/9, 4/3, 1 for square.
class_name
Type
string
Default: ""
Additional CSS classes to apply to the root element.