I’ve learned that it is a best practice to explicitly specify image dimensions. The browser can then already layout the page while still downloading the images themselves, thereby improving (percieved) page rendering time.
Is this true? And if so, is there a difference in specifying the dimensions in either HTML or CSS?
- HTML:
<img src="" width="200" height="100"> - Inline CSS:
<img src="" style="width: 200px; height: 100px"> - External CSS:
#myImage { width: 200px; height: 200px; }
According to Google Page Speed, it does not really matter if you specify the dimensions via CSS or HTML, as long as your CSS targets the IMG tag itself and not a parent element :
However, note that they advise not to resize the image using these dimensions, ie to always use the real dimensions :