Skip to main content
Version: 1.0.3

AspectRatio

The AspectRatio component ensures that its children maintain a specific width-to-height ratio, making it ideal for videos, images, or placeholders that need to be consistently sized across devices.

Preview

Demo Image

Installation

ignix add component aspectratio

Usage

Import the component:

import { AspectRatio } from '@ignix-ui/aspectratio';

Basic Usage

function BasicAspectRatio() {
return (
<AspectRatio ratio="4:3" maxWidth="500px">
<img src="https://thumbs.wbm.im/pw/medium/859204cf5b71808ed4c6bd19d95974c6.jpg" alt="Demo Image" />
</AspectRatio>
);
}

Props

PropTypeDefaultDescription
ratio"1:1" | "4:3" | "16:9" | "21:9" | string"1:1"The width-to-height ratio. Accepts any custom "W:H" string
maxWidthstring | number-Maximum width of the container. (e.g. "50%", "30rem", "400px"). Numbers are auto-converted to px
childrenReact.ReactNoderequiredContent rendered inside the ratio container. Direct <img> children automatically receive object-cover w-full h-full