Skip to content
GitHub11 stars

Displays content within a desired ratio.

Photo
<AspectRatio Ratio="@(16.0 / 9)" Class="w-full max-w-sm rounded-lg bg-muted">
    <img src="https://avatar.vercel.sh/blazix1" alt="Photo" class="absolute inset-0 size-full rounded-lg object-cover grayscale dark:brightness-20" />
</AspectRatio>

Installation

dnx Blazix.Cli add aspect-ratio

Usage

<AspectRatio Ratio="@(16.0 / 9)"><img src="..." alt="Image" class="rounded-md object-cover" /></AspectRatio>

Square

A square aspect ratio component using the Ratio="@(1.0 / 1)" parameter. This is useful for displaying images in a square format.

Photo
<AspectRatio Ratio="@(1.0 / 1)" Class="w-full max-w-[12rem] rounded-lg bg-muted">
    <img src="https://avatar.vercel.sh/blazix1" alt="Photo" class="absolute inset-0 size-full rounded-lg object-cover grayscale dark:brightness-20" />
</AspectRatio>

Portrait

A portrait aspect ratio component using the Ratio="@(9.0 / 16)" parameter. This is useful for displaying images in a portrait format.

Photo
<AspectRatio Ratio="@(9.0 / 16)" Class="w-full max-w-[10rem] rounded-lg bg-muted">
    <img src="https://avatar.vercel.sh/blazix1" alt="Photo" class="absolute inset-0 size-full rounded-lg object-cover grayscale dark:brightness-20" />
</AspectRatio>

RTL

To enable RTL support in Blazix, see the RTL configuration guide.

Translated with AI for the demo, so it may have mistakes.

صورة
منظر طبيعي جميل
<figure class="w-full max-w-sm">
    <AspectRatio Ratio="@(16.0 / 9)" Class="rounded-lg bg-muted">
        <img src="https://avatar.vercel.sh/blazix1" alt="@T.Alt" class="absolute inset-0 size-full rounded-lg object-cover grayscale dark:brightness-20" />

API Reference

AspectRatio

ParameterTypeDefault
Ratiorequired double 1
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.