HTML image sizing

Is it good practice to set the image size (in static content) even if I cut the image to the right size and the container has fixed sizes and overflow: hidden?

<img src="" title ="" alt="" width="100" height="100"/> 
+4
source share
2 answers

As a rule, you should specify height and width labels so that the browser can reserve the necessary space for the image. Otherwise, the layout may change during page loading.

Since you have a container with a fixed size and overflow: hidden, it probably won't help. But even if this does not help, it will not hurt either. Therefore, you should adhere to always adding height and width attributes.

http://www.w3schools.com/tags/att_img_width.asp (see tips in the Definition and Use section for tips)

+3
source

I don't have hard data to back it up, but I think I saw browsers that showed a rectangle in the image until the actual image loads. To correctly display a rectangular area, the browser will need the width and height of the data.

In addition, some browsers will display a rectangle instead of an image when images are disabled or cannot be downloaded. Correct rectangle calibration also requires size information.

I think it will not hurt to install it.

+1
source

Source: https://habr.com/ru/post/1314533/


All Articles