ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

Responsive Web Design, Colors & UI Systems• 6 min read

Responsive Images & aspect-ratio

Optimize web images using srcset, the picture element, and modern CSS aspect-ratio to eliminate Cumulative Layout Shift (CLS).

Eliminating Layout Shift with aspect-ratio

Before an image downloads, the browser does not know its dimensions, causing page content to jump downward when the image finally renders (CLS). Setting aspect-ratio: 16 / 9; reserves the exact space immediately.

Zero-CLS Responsive Image Container
img.responsive-hero {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
}
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Which modern CSS property reserves space for an image before it downloads to prevent Cumulative Layout Shift (CLS)?