PLW
PLW

Reputation: 200

Setting width and height attributes on <img> element on responsive images

I understand that currently we are supposed to use width and height attributes on <img> elements again, mostly to avoid or minimize layout shift. And this works OK when I have images with the same set dimensions across all screen sizes.

But what do I do in the following situations:

I tried searching for answers online, obviously, but in most cases I can only find articles convincing me how important it is to use these attributes, or, that this is a hassle now, but will be much easier once aspect-ratio is introduced and implemented in the browsers. So, not very useful so far.

In other words, let's say I have an image that is:

What would I put in the width="X" height="X" attributes?

Upvotes: 2

Views: 845

Answers (1)

PLW
PLW

Reputation: 200

Ok, so after quite extensive research and experimentation I've found out that, in truth, it doesn't really matter as long as the aspect ratio is preserved. So the best bet would probably be to use image's original dimensions.

Upvotes: 2

Related Questions