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;" />
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;" />
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">