Performance: Ratio utilities for embeds
This affects the page's layout stability and loading speed by controlling the aspect ratio of embedded content without extra scripts.
<div class="ratio ratio-16x9"> <iframe src="https://www.youtube.com/embed/zpOULjyy-n8" title="Video embed" allowfullscreen></iframe> </div>
<iframe src="https://www.youtube.com/embed/zpOULjyy-n8" style="width:100%; height:auto;"></iframe>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Iframe without ratio container | Minimal DOM nodes | Multiple reflows on load | Higher paint cost due to layout shifts | [X] Bad |
| Iframe inside Bootstrap ratio utility | One extra div node | Single reflow with reserved space | Lower paint cost, stable layout | [OK] Good |
ratio utility classes like ratio-16x9?ratio-16x9 set the width and height ratio so the content scales properly on different screen sizes.div with class ratio plus the aspect ratio class like ratio-4x3 wrapping the embedded content.iframe should not have the ratio class directly; it must be inside the div with the ratio classes.<div class='ratio ratio-1x1'> <iframe src='https://example.com' title='Example'></iframe> </div>
ratio-1x1 sets the aspect ratio to 1:1, which means width equals height, making the embed square.div with ratio classes, the iframe scales responsively to fit its container while keeping the square shape.<div class='ratio-16x9'> <iframe src='video.mp4'></iframe> </div>
ratio along with the aspect ratio class like ratio-16x9.ratio-16x9 but is missing the base ratio class, so the aspect ratio styling won't apply correctly.ratio on the wrapper div -> Option Bratio-1x1 ensures the embed is a perfect square on all devices.shadow-sm should be added to the same wrapper div that holds the ratio classes to apply the shadow around the embed.iframe should be inside the div with both ratio and shadow-sm classes. Applying ratio classes directly on iframe is incorrect.Pass the test and this pattern moves unknown