Course contentsShow
← Web Development
Lesson 1896 of 2,98235. Web Performance FundamentalsFree lesson

Calculating CLS: Impact Fraction and Distance Fraction

Learning how CLS is computed from viewport changes and element movement distances.

Calculating CLS: Impact Fraction and Distance Fraction

You'll learn how CLS scores are computed from the two key components: how much of the viewport is affected and how far elements move.

The Two-Part Formula

Cumulative Layout Shift doesn't just measure that something moved—it measures how much of the screen was affected and how far things shifted. The CLS score for each layout shift is calculated by multiplying two fractions:

layout shift score = impact fraction × distance fraction

Impact Fraction: What Percentage of Viewport Is Affected?

The impact fraction represents the total area of the viewport that experienced instability. If an element occupies 20% of the viewport and then shifts, affecting additional space, the impact fraction includes both the original and new positions combined.

Analogy: Imagine a water stain spreading on paper. The impact fraction measures the total area covered by both the original stain and where it spreads to.

For example, if an element takes up 30% of the viewport height and shifts down by 10% of the viewport, the impact fraction would be 0.40 (40% total affected area).

Distance Fraction: How Far Did Elements Move?

The distance fraction is the greatest distance any unstable element moved, divided by the viewport's largest dimension (width or height).

If an image shifts down 150px on a viewport that's 1000px tall, the distance fraction is 150 / 1000 = 0.15.

Putting It Together

CLS score = 0.40 (impact) × 0.15 (distance) = 0.06

This calculation happens for each layout shift during a session window, and those scores are summed to produce the final CLS metric.

Key Takeaway: CLS scores combine how much viewport area experienced layout instability (impact fraction) with how far elements moved (distance fraction), giving higher penalties to large shifts that affect more of the screen.