The CSS Podcast cover image

The CSS Podcast

71: Why do I have layout shift?

Aug 31, 2023
Guest Una Kravets, Web DevRel @googlechrome, discusses layout shift in CSS, including different types of shifts, mitigating image load layout shift, effects of JavaScript and lazy loading, and combating layout shift using CSS.
11:30

Episode guests

Podcast summary created with Snipd AI

Quick takeaways

  • Cumulative layout shift (CLS) measures the instability of a webpage's content caused by various factors like images, iframes, animations, and fonts, and can be mitigated by specifying sizes for elements, lazy loading, and using CSS grids.
  • There are three main types of layout shifts: load layout shift, post load layout shift, and expected layout shift, each impacting content stability and user experience, and field testing on actual devices can help in identifying and reducing CLS.

Deep dives

Understanding Cumulative Layout Shift (CLS)

Cumulative layout shift (CLS) is a key performance metric that measures the instability of a webpage's content. It penalizes experiences where content shifts, jumps, or moves while users are interacting with it. This can be frustrating, especially when it causes buttons to shift and gets clicked accidentally. CLS can be caused by various factors such as images, iframes/ads without dimensions, late-loaded third-party content, animations, and fonts. To mitigate CLS, it is important to specify sizes for images and iframes, lazy load CSS and fonts properly, and use CSS grids to define and allocate layout space. Interactions like focus or hover can also trigger layout shifts. Testing and debugging CLS can be done using tools like Lighthouse, which identifies offending elements and provides recommendations to reduce CLS. Performance Panel in DevTools can also highlight layout shifts on the page and show timing data.

Get the Snipd
podcast app

Unlock the knowledge in podcasts with the podcast player of the future.
App store bannerPlay store banner

AI-powered
podcast player

Listen to all your favourite podcasts with AI-powered features

Discover
highlights

Listen to the best highlights from the podcasts you love and dive into the full episode

Save any
moment

Hear something you like? Tap your headphones to save it with AI-generated key takeaways

Share
& Export

Send highlights to Twitter, WhatsApp or export them to Notion, Readwise & more

AI-powered
podcast player

Listen to all your favourite podcasts with AI-powered features

Discover
highlights

Listen to the best highlights from the podcasts you love and dive into the full episode