Jump to content

HTML5 img element


caffinated

Recommended Posts

I'm new so I guess it is polite to say Hello.I recently had a validation error via W3C on an HTML5 page telling me that it found a "%" value when an integer was expected for an image width attribute.I was pretty sure that in XHTML percentage values were allowed, so I came to the user-friendly layout of W3Schools to double check. Sure enough, W3Schools does state that percentage values are acceptable. HTML5 img element pageHowever, according to W3C,

The width and height attributes on img, iframe, embed, object, video, and, when their type attribute is in the Image Button state, input elements may be specified to give the dimensions of the visual content of the element (the width and height respectively, relative to the nominal direction of the output medium), in CSS pixels. The attributes, if specified, must have values that are valid non-negative integers.
Here is the W3C page There is no mention of percentage values, so I suspect the W3Schools entry may need adjusting.If not, I would appreciate being corrected and provided with the correct reference that states percentage values are allowed, so that I may challenge W3C about their validator.
Link to comment
Share on other sites

It seems the validator is correct. The img element section of Recommendation specifies that width and height attributes must be unsigned long integer values. There is no mention of relative values. This sentence links us to the section describing image maps:The img element supports dimension attributeswhere we find this extremely specific sentence:The dimension attributes are not intended to be used to stretch the image.I wondered at first if the rules applied only to image maps, but all references to image dimensions that I could find currently lead to the map section.On the other hand, I can find no rules in the current draft of CSS3 indicating that relative values cannot be applied to images in a stylesheet. That doesn't mean such rules don't exist. Just that I looked for a while and couldn't find any.

Link to comment
Share on other sites

Interesting Diedre'sDad. You're correct about the CSS route. If I remove the dimension attributes from the HTML img element but add a percentage attribute to the CSS for the image, both the HTML and the CSS validate. This makes a mockery of the HTML spec really.However, it still means that the W3Schools entry is incorrect. Percentage is not valid for HTML5 img dimension attributes.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...