DEV Community

Derek Kahre
Derek Kahre

Posted on

Fixing the "Invisible" Accessibility Bug: Cumulative Layout Shift (CLS)

A person looking at and using a Computer
When we think about web accessibility, we usually think about adding alt text to images or ensuring color contrast is high enough. But this week, while building out the skeleton for a responsive, accessible toy store project, a strict scanner taught me about an "invisible" accessibility bug that completely changes how a page feels to a user.

I deployed my initial HTML structure to GitHub Pages and ran it through Powermapper (SortSite). While basic checkers gave me a pass, Powermapper flagged a warning about missing image width and height dimensions.

At first glance, it feels like a minor layout issue, but it's actually an accessibility hurdle known as Cumulative Layout Shift (CLS).

The Problem: Jumping Layouts
When you omit image dimensions, the browser assumes the image takes up 0 pixels of space until the file completely downloads. The moment the image pops in, it violently pushes all the content below it down the screen.

For a user utilizing screen magnification software, or someone with motor-control challenges trying to click a button, that sudden "jump" can make them completely lose their place or accidentally click the wrong element.

The "A-Ha" Fix
To fix this without breaking your responsive design on mobile, you have to let the browser pre-calculate the aspect ratio box before the image loads. You do this by combining native HTML attributes with a tiny splash of CSS.

Here is the exact pattern that cleared the error:

HTML

<br> /* This ensures the image stays fluid and shrinks on mobile screens */<br> img { <br> max-width: 100%; <br> height: auto; <br> }<br>


<!-- Hardcoding the native dimensions lets the browser reserve the exact space -->
alt="Set of rocks with distinct tactile textures."
width="300"
height="300">

By putting the dimensions back in the HTML, the browser leaves a perfect placeholder box open while the image downloads. No shifting, no jumping, and a completely stable reading experience.

If you are auditing your own junior projects, I highly recommend throwing them into a stricter scanner like Powermapper to see what layout vulnerabilities might be hiding in plain sight.

Hopefully, this saves someone else a few hours of head-scratching today! What's an "invisible" bug a compiler or scanner has caught for you recently?

Top comments (0)