Search code examples
htmlvalidationsemantic-markup

Confused with HTML validation error


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!


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