Step 5: Layout Shift Issues

The Problem

When images load without specified dimensions, they cause layout shifts as the browser doesn't know how much space to reserve. This affects the Cumulative Layout Shift (CLS) metric.

Issues:

  • Content jumps as images load
  • Poor user experience
  • High CLS score (bad for Core Web Vitals)
  • No image optimization

Problematic Code:


<div class="card">
  <img
    [src]="card.imageUrl"
    [alt]="card.title"
  >
  <h3>{{ card.title }}</h3>
</div>
          

Watch how the layout shifts as images load. Try scrolling while images are loading to experience the poor user experience. Open DevTools Performance tab and look for layout shifts.

Card 1

Card 1

Card 2

Card 2

Card 3

Card 3

Card 4

Card 4

Card 5

Card 5

Card 6

Card 6

Card 7

Card 7

Card 8

Card 8

Card 9

Card 9

Card 10

Card 10

Card 11

Card 11

Card 12

Card 12

Card 13

Card 13

Card 14

Card 14

Card 15

Card 15

Card 16

Card 16

Card 17

Card 17

Card 18

Card 18

Card 19

Card 19

Card 20

Card 20