Skip to content
HTML·Intermediate·Conceptual·1 min read

Why do width and height attributes matter even though CSS controls the final rendered size?

Short interview answer

They let the browser compute the image's aspect ratio before the file has downloaded, so it can reserve the correct box in layout immediately; omitting them causes surrounding content to jump once the image loads, which is measured as layout shift.

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Images, media, and responsive assets

Related questions