Question

I have this code:

<img src="Media//Service//rightImage.jpg" alt="Watch Repair" width="380px" height="272px" style="float:right;" />

and the HTML validation tool on the w3.org website I am using is saying that I cannot use a width of "380px" because:

Bad value 380px for attribute width on element img: Expected a digit but saw p instead. …ge.jpg" alt="Watch Repair" width="380px" height="272px" style="float:right;" /> Syntax of non-negative integer: One or more digits (0–9). For example: 42 and 0 are valid, but -273 is not.

Does this mean I should just delete the px part and it will run fine? I thought I have to define the width as pixels?

Very confused! Can anyone explain this to me? Thanks guys!

Was it helpful?

Solution

You don't need to write "px" with width or height property of img

The width attribute specifies the width of an image, in pixels.

just write something like this

<img src="Media//Service//rightImage.jpg" alt="Watch Repair" width="380" height="272" style="float:right;" />

and the preferred way is to use style property to define these properties

<img src="Media//Service//rightImage.jpg" alt="Watch Repair" style="width:380px;height:272px;float:right;" />

OTHER TIPS

Yes, its very trivial. You'd have to delete the px part and leave the numbers, they are always in pixels anyway. http://www.w3schools.com/tags/att_img_width.asp

A related thread for this which would help others: Image width/height as an attribute or in CSS?

Another on the same is: Should image size be defined in the img tag height/width attributes or in CSS?

By HTML5 rules, the dimension attributes, if used, must have values that are valid non-negative integers. No unit is needed, or accepted. The implied unit is CSS pixel. So yes, you should simply remove the px parts.

remove 'px' from height & width attributes

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top