Should I add the height and width to the img src tag?

Updated: 04/26/2017 by Computer Hope

Yes. Adding the height and width attributes to your IMG SRC HTML tag allows the browser to know how much space to leave for an image. Without these values, the browser gives an image no space until the image is loaded, which means anything surrounding the image is adjusted after the image has loaded.

Image size dimensions specified in img tag

As seen in the above example, the first three pages show a page loading that does not specify the image dimensions. As the pages loads, the text surrounding the images is adjusted to accommodate the image. However, with the image dimensions specified, as shown in the next three pages, the browser knows how much space to allocate. Therefore, the text remains in the same place as the images load.

If you have a fast Internet connection you may not notice this loading process. However, for people with slow connections, browsing on a phone, or if your site is loading slow if you do not specify the image sizes you make it even more difficult for these visitors.

Below is an example of how an IMG tag should look in your HTML code with the height and width specified in the code.

<img src="pictures/image-size.jpg" width="637" height="613" alt="Image size dimensions">

Additional information