Home
Do you *not* have height/width in an <img> tag?
  v6.0 Posted at 22/12/2015 3:25 AM by Tiago Araujo

The <img> tag of HTML has 2 attributes that should not be used - "height" and "width".  Any image resizing should  be done via CSS. If the height / width ratio doesn't match that of original image, the image will be stretched.

<img src="images/codeauditor-logo.png" alt="Code Auditor logo" width="150" height="100" />​

Stretched image which looks ugly
Figure: Bad example - Stretched image caused by inline​ height/width ratio that doesn't match

<img src="images/codeauditor-logo.png" alt="Code Auditor logo"  />​​​​

Image looks fine
Figure: Good example - Avoiding inline​ height/width ratio keeps the image as original

We have a program called SSW Code Auditor to check for this rule.

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments: