Use ratio helpers to create responsive containers that maintain a specific aspect ratio. Perfect for videos, maps, and embedded content that must scale proportionally.
Bootstrap provides four predefined ratios. Apply the .ratio base class
along with a modifier class like .ratio-16x9.
.ratio-1x1 (Square).ratio-4x3 (Standard).ratio-16x9 (Widescreen).ratio-21x9 (Ultra-wide)
Wrap <iframe> elements in a ratio container for responsive video embeds.
Always include a title attribute for accessibility.
Most YouTube videos use 16:9 aspect ratio. The iframe automatically fills the container.
Use ratio containers with placeholder content before videos load or for preview states.
Maps often work well in 4:3 or 16:9 ratios. Add loading="lazy" for performance.
Create custom ratios using the --bs-aspect-ratio CSS variable.
The formula is: (height / width) * 100%.
--bs-aspect-ratio: 50%;
--bs-aspect-ratio: calc(2 / 3 * 100%);
--bs-aspect-ratio: 80%;
--bs-aspect-ratio: calc(height / width * 100%)
calc(9 / 16 * 100%) = 56.25%calc(3 / 4 * 100%) = 75%calc(1 / 2 * 100%) = 50%Combine ratio containers with Bootstrap's sizing and spacing utilities for flexible, responsive layouts.
Use max-width and .mx-auto to constrain and center.
Ratio containers work seamlessly within Bootstrap's grid system.
Ratio containers keep thumbnails consistent.
<iframe> elements must have a descriptive
title attribute for screen readers.
<div class="ratio ratio-16x9">
<iframe
src="https://www.youtube.com/embed/VIDEO_ID"
title="Introduction to Bootstrap 5 - Tutorial Video"
allow="accelerometer; autoplay; clipboard-write; encrypted-media"
allowfullscreen></iframe>
</div>
title attribute describes the embedded contentloading="lazy" for below-the-fold contentCombine ratio helpers with other Bootstrap utilities for complex layouts.