Chapter 4. Understanding Layout Shift and Ads

Why Ads Cause Layout Shift

When you paste AdSense's code into a page, it adds an empty element. The browser gives an empty element no height. The AdSense script then asks Google for an ad, and only when the answer comes back does the element get its real size, often 250 or 300 pixels tall. Everything below it moves down by that much.

Your own images don't have this problem when they have a width and height, because the browser can work out their size before they load. An ad has no size until Google decides which ad to show. The only way to stop it from moving your content is to keep space for it in advance.