Primals
Ratio

Ratio

The Ratio component is a utility component that allows you to maintain a specific aspect ratio for a container. This is particularly useful when you want to ensure that the width and height of a container are proportional, such as for responsive image or video containers. The aspect ratio is controlled via a prop, allowing for flexible and reusable layout designs.

<Ratio ratio="16/9">
  <img src="https://via.placeholder.com/1920x1080" alt="Placeholder" className="object-cover h-full" />
</Ratio>

Props

PropTypeDescription
backgroundColorstringThe background color of the Ratio component.
bgstringThe background color of the Ratio component.
childrenReactNodeThe content of the Ratio component.
hstringThe height of the Ratio component.
heightstringThe height of the Ratio component.
mnumberThe margin around the Ratio component.
marginnumberThe margin around the Ratio component.
mbnumberThe bottom margin of the Ratio component.
mlnumberThe left margin of the Ratio component.
mrnumberThe right margin of the Ratio component.
mtnumberThe top margin of the Ratio component.
mxnumberThe horizontal margin of the Ratio component.
mynumberThe vertical margin of the Ratio component.
pnumberThe padding around the Ratio component.
paddingnumberThe padding around the Ratio component.
pbnumberThe bottom padding of the Ratio component.
plnumberThe left padding of the Ratio component.
prnumberThe right padding of the Ratio component.
ptnumberThe top padding of the Ratio component.
pxnumberThe horizontal padding of the Ratio component.
pynumberThe vertical padding of the Ratio component.
radiusnumberThe border radius of the Ratio component.
rationumber | phone | fullscreen | widescreen | golden | ultrawide | half | third ... twelfth | half-y | third-y ... twelfth-y | portrait | landscapeThe aspect ratio of the Ratio component.
ratioXnumberThe horizontal aspect ratio of the Ratio component.
ratioYnumberThe vertical aspect ratio of the Ratio component.
wstringThe width of the Ratio component.
widthstringThe width of the Ratio component.

Examples

Any of the examples below can be done either with the ratio prop or with the ratioX and ratioY props.

Square 1/1 Ratio

Placeholder

Phone 6/13 Ratio

Placeholder

Fullscreen 4/3 Ratio

Placeholder

Widescreen 16/9 Ratio

Placeholder

Golden 16/10 Ratio

Placeholder

Ultrawide 21/9 Ratio

Placeholder

Half 1/2 Ratio

Placeholder

Third 1/3 Ratio

Placeholder

Twelfth 1/12 Ratio

Placeholder

Half-y 2/1 Ratio

Placeholder

Third-y 3/1 Ratio

Placeholder

Twelfth-y 12/1 Ratio

Placeholder

Portrait 3/4 Ratio

Placeholder

Landscape 4/3 Ratio

Placeholder

Custom 3/2 Ratio

Placeholder

Custom 2/3 Ratio

Placeholder