Loading...
Skip to main content

Aspect ratio

Make elements maintain specific aspect ratios. Perfect for handling videos, slideshow embeds, and more based on the width of the parent.

Idea React provides the Ratio wrapper for Bootstrap's aspect-ratio utilities. Set aspectRatio to auto, 1x1, 4x3, 16x9, or 21x9, and use as to apply the utility directly to an element such as an iframe. The default is 1x1.

Ratio supports embedded media and other elements through its as prop.

Example

Apply a ratio to an embedded video. The Ratio root is the iframe itself, so the browser sizes it according to the selected aspect ratio.

Swap aspectRatio for another predefined value:

Auto
1×1
4×3
16×9
21×9

Custom ratios

Pass a CSS aspect ratio such as "2 / 1" to aspectRatio for a custom ratio. The wrapper uses Bootstrap's --bs-ratio custom property and the ratio-auto utility. You can also override that property at breakpoints in your own CSS.

2×1

For example, define a breakpoint-specific ratio in your stylesheet:

.custom-ratio {
--bs-ratio: 4 / 3;
}

@media (min-width: 768px) {
.custom-ratio {
--bs-ratio: 2 / 1;
}
}

Apply the class along with aspectRatio="auto":

4×3, then 2×1

Documentation navigation
On this page
On this page