0
0
Bootsrapmarkup~10 mins

Ratio utilities for embeds in Bootsrap - Browser Rendering Trace

Choose your learning style9 modes available
Render Flow - Ratio utilities for embeds
Read HTML with embed container
Apply Bootstrap ratio utility class
Calculate aspect ratio from class (e.g., 16:9)
Set container height relative to width
Embed content fills container preserving ratio
Browser paints embed with correct size
The browser reads the embed container with a Bootstrap ratio class, calculates the aspect ratio, sets the container's height based on its width, and then sizes the embedded content to fill the container while preserving the ratio.
Render Steps - 4 Steps
Code Added:<div class="ratio ratio-16x9"> ... </div>
Before
[ ] (empty space, no embed container)
After
[________________________]
|                        |
|                        |
|                        |
|                        |
|________________________|
Adding the ratio container creates a box that will hold the embed and control its size.
🔧 Browser Action:Creates a block container with width 100% and relative positioning.
Code Sample
A responsive container that keeps a 16:9 aspect ratio for the embedded YouTube video, resizing smoothly with the page width.
Bootsrap
<div class="ratio ratio-16x9">
  <iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" title="YouTube video" allowfullscreen></iframe>
</div>
Bootsrap
.ratio {
  position: relative;
  width: 100%;
}
.ratio > * {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
Render Quiz - 3 Questions
Test your understanding
After applying step 3, what visual effect does the .ratio-16x9 class have on the container?
AIt fixes the container height to 100px.
BIt sets the container height automatically to keep a 16:9 ratio with its width.
CIt makes the container invisible.
DIt centers the container horizontally.
Common Confusions - 2 Topics
Why does my embed stretch and look distorted?
If the embed is not inside a container with the correct aspect ratio or the embed itself is not set to fill the container, it will stretch. The ratio container sets the height automatically to keep the ratio.
💡 Always wrap embeds in a .ratio container and set embed to position:absolute with width and height 100%.
Why doesn't the container have any height?
Without the aspect-ratio property or padding trick, the container collapses because it has no content height. The ratio utility sets height based on width to prevent collapse.
💡 Use aspect-ratio or padding-bottom trick to keep container height.
Property Reference
PropertyValue AppliedEffect on LayoutCommon Use
positionrelativeCreates positioning context for absolute childrenContainer for embed
width100%Container fills available horizontal spaceResponsive width
aspect-ratio16 / 9Sets height based on width to keep ratioMaintain video ratio
positionabsoluteChild fills container exactlyEmbed fills ratio box
top, left0Aligns child to container top-left cornerPosition embed
width, height100%Child fills entire container areaEmbed sizing
Concept Snapshot
Bootstrap ratio utilities keep embedded content like videos responsive. Use .ratio and .ratio-16x9 (or other ratios) to set container aspect ratio. The container uses position:relative and aspect-ratio to size itself. Embed inside uses position:absolute and fills container with width/height 100%. This prevents distortion and keeps embeds looking good on all screen sizes.