What's the difference between the HTML width / height attribute and the CSS width / height property on the img element?

A hot debate about the subject can be found here: Width attribute for image tag versus CSS

To sum it up:

The gain from declaring a width value and an height value (which may not be the original physical dimensions of the image) or from css declarations (like width: [valueX]; height: [valueY];) is that it helps speed up the rendering of the page. The browser knows how much space to allocate a particular area of the page: it will even draw image placeholders on a first draw, a first parsing+rendering of the page. When one does not define any width and height, then the browser has to download the image and then figure out its dimensions, space to allocate and then redraw the page.

This seems to be the most beneficial effect in my opinion.


They have the same effect.

<img width="100" height="100" /> has been used for a long time, same with the widht/height properties of say.. an HTML table.

There is no difference whether you specify it on the element itself or within the CSS, though I now prefer using CSS so I can keep the HTML clear and concise.

Here's an example http://jsfiddle.net/N2RgB/1/

I've loaded the same image 4 times, both proportional and non-proportional using HTML attributes AND CSS properties.

There is absolutely NO difference.


I made a comparison up at: http://jsfiddle.net/jF8y6/ with 4 different states. The main difference is the way it is used via external stylesheets in terms of the ability to resize images for different stylesheets (desktop, mobile, print, etc) and the flexibility it brings. If you hardcode the sizes then it stops the flexibility.