HTML5 - Can I use Width and Height in IMG?

Viewed 55416

It is Legal to use this code:

<img src="...(here image)...." width="50px" height="50px" />

Or I need to use:

<img src="...(here image)..." style="width: 50px; height: 50px;" />
6 Answers

Google Pagespeed Insights recommends the first one to reduce layout shifting. As others have mentioned, it can be overridden easily with CSS, e.g. for responsive pages.

Also, HTML 5 doesn't support self-closing tags (/ at end) so best format would be:

<img src="...(here image)...." width="50" height="50">

Related