<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/why-width-and-height-still-matter-for-html-images-gfwjovmpc" -->

---
title: Why width and height Still Matter for HTML Images
description: Explains why the width and height HTML attributes on <img> elements matter for preventing Cumulative Layout Shift, even in responsive designs using CSS. Covers...
canonical: https://daily.dev/posts/why-width-and-height-still-matter-for-html-images-gfwjovmpc
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Why width and height Still Matter for HTML Images | daily.dev
og:description: Explains why the width and height HTML attributes on <img> elements matter for preventing Cumulative Layout Shift, even in responsive designs using CSS. Covers...
og:url: https://daily.dev/posts/why-width-and-height-still-matter-for-html-images-gfwjovmpc
og:image: https://api.daily.dev/og/posts/GfWjovmpc.png
og:image:alt: Why width and height Still Matter for HTML Images
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Why width and height Still Matter for HTML Images

**[JS Dev Space](https://daily.dev/sources/jsdev-space)** · 10 min read · 14 upvotes · 2 comments

## Summary

Explains why the width and height HTML attributes on <img> elements matter for preventing Cumulative Layout Shift, even in responsive designs using CSS. Covers how browsers use these attributes to compute an intrinsic aspect ratio and reserve space before images load, the difference between HTML dimensions and CSS aspect-ratio, the old padding-bottom hack, lazy-loaded images, <picture> element sizing, and how to test layout shifts using Chrome DevTools.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://jsdev.space/image-width-height>

## Questions this post answers

### Do I still need width and height attributes on img tags if I'm using responsive CSS like max-width: 100%?

Yes, width and height attributes should still be included even with responsive CSS. They provide the browser with the image's intrinsic aspect ratio so it can reserve the correct amount of space before the file finishes downloading, preventing layout shifts. CSS like max-width: 100% and height: auto then controls the displayed size while preserving that ratio.

_Developers optimizing Core Web Vitals compare real-world CLS fixes like this on daily.dev._

### What is the difference between using HTML width/height attributes and CSS aspect-ratio for images?

HTML width and height attributes describe the intrinsic dimensions of the actual image resource, letting the browser compute its native aspect ratio before the file loads. CSS aspect-ratio instead enforces a shape at the component or layout level, useful when a thumbnail grid needs uniform frames regardless of each photo's original proportions, often paired with object-fit: cover for cropping.

_Anyone deciding between layout techniques can weigh these tradeoffs alongside other frontend patterns on daily.dev._

### Why was the padding-bottom 56.25% hack used for responsive video and image containers before CSS aspect-ratio existed?

The padding-bottom percentage hack reserved responsive space for a fixed aspect ratio by exploiting the fact that percentage padding is calculated relative to an element's width. For a 16:9 ratio, 9 divided by 16 times 100 equals 56.25%, so setting padding-bottom to that value created a box with the correct proportions before the modern aspect-ratio CSS property was available.

_Frontend engineers modernizing legacy CSS patterns can track such changes over time on daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@theace92** · 3 upvotes

> Pretty good article. Covers the basics and gives good examples and explanations, 16/9 🤪

## Similar posts on daily.dev

- [The CSS aspect-ratio property and the math behind it](https://daily.dev/posts/the-css-aspect-ratio-property-and-the-math-behind-it-zuquamsi6) · Flavio Copes · 3 upvotes · 1 comments
- [Responsive Images in WordPress: What You Need to Know](https://daily.dev/posts/responsive-images-in-wordpress-what-you-need-to-know-6e2xqgdyf) · WP Mayor · 0 upvotes · 0 comments
- [Ending Responsive Images](https://daily.dev/posts/ending-responsive-images-jvntuvxno) · Cloud Four · 88 upvotes · 4 comments
- [Something Nobody Told You About The Image Element \(It Can Overflow\!\) – Master.dev Blog](https://daily.dev/posts/something-nobody-told-you-about-the-image-element-it-can-overflow-master-dev-blog-l4xennisc) · Frontend Masters · 2 upvotes · 1 comments

---

Tags: [#webdev](https://daily.dev/tags/webdev), [#css](https://daily.dev/tags/css), [#html](https://daily.dev/tags/html)

[View this post on daily.dev](https://daily.dev/posts/why-width-and-height-still-matter-for-html-images-gfwjovmpc)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Why width and height Still Matter for HTML Images","url":"https://daily.dev/posts/why-width-and-height-still-matter-for-html-images-gfwjovmpc","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/why-width-and-height-still-matter-for-html-images-gfwjovmpc"},"datePublished":"2026-09-16T13:12:36.990Z","dateModified":"2026-09-16T13:21:20.782Z","description":"Explains why the width and height HTML attributes on \u003cimg\u003e elements matter for preventing Cumulative Layout Shift, even in responsive designs using CSS. Covers...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/da6251ab143d71f5f041ab8fe6f7bff5?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/da6251ab143d71f5f041ab8fe6f7bff5?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"JS Dev Space","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"JS Dev Space","logo":"https://media.daily.dev/image/upload/s--c6lsvtKD--/f_auto,q_auto/v1774960839/logos/jsdev-space?_a=BAMAMiWQ0","url":"https://daily.dev/sources/jsdev-space"},"commentCount":2,"discussionUrl":"https://daily.dev/posts/why-width-and-height-still-matter-for-html-images-gfwjovmpc","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":14},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":2}],"keywords":"webdev,css,html","timeRequired":"PT10M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"JS Dev Space","item":"https://daily.dev/sources/jsdev-space"},{"@type":"ListItem","position":3,"name":"Why width and height Still Matter for HTML Images"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/why-width-and-height-still-matter-for-html-images-gfwjovmpc","comment":[{"@type":"Comment","text":"Pretty good article. Covers the basics and gives good examples and explanations, 16/9 🤪","datePublished":"2026-09-17T04:46:24.762Z","url":"https://daily.dev/posts/GfWjovmpc#c-Rt6WyoqB9","author":{"@type":"Person","name":"Theace","url":"https://daily.dev/theace92","image":"https://avatars.githubusercontent.com/u/211419990?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/why-width-and-height-still-matter-for-html-images-gfwjovmpc#faq","mainEntity":[{"@type":"Question","name":"Do I still need width and height attributes on img tags if I'm using responsive CSS like max-width: 100%?","acceptedAnswer":{"@type":"Answer","text":"Yes, width and height attributes should still be included even with responsive CSS. They provide the browser with the image's intrinsic aspect ratio so it can reserve the correct amount of space before the file finishes downloading, preventing layout shifts. CSS like max-width: 100% and height: auto then controls the displayed size while preserving that ratio. Developers optimizing Core Web Vitals compare real-world CLS fixes like this on daily.dev."}},{"@type":"Question","name":"What is the difference between using HTML width/height attributes and CSS aspect-ratio for images?","acceptedAnswer":{"@type":"Answer","text":"HTML width and height attributes describe the intrinsic dimensions of the actual image resource, letting the browser compute its native aspect ratio before the file loads. CSS aspect-ratio instead enforces a shape at the component or layout level, useful when a thumbnail grid needs uniform frames regardless of each photo's original proportions, often paired with object-fit: cover for cropping. Anyone deciding between layout techniques can weigh these tradeoffs alongside other frontend patterns on daily.dev."}},{"@type":"Question","name":"Why was the padding-bottom 56.25% hack used for responsive video and image containers before CSS aspect-ratio existed?","acceptedAnswer":{"@type":"Answer","text":"The padding-bottom percentage hack reserved responsive space for a fixed aspect ratio by exploiting the fact that percentage padding is calculated relative to an element's width. For a 16:9 ratio, 9 divided by 16 times 100 equals 56.25%, so setting padding-bottom to that value created a box with the correct proportions before the modern aspect-ratio CSS property was available. Frontend engineers modernizing legacy CSS patterns can track such changes over time on daily.dev."}}]}
```

