Welcome to WebmasterWorld Guest from

Forum Moderators: incrediBILL

Message Too Old, No Replies

HTML5 img element

Percentage dimension values not allowed



4:14 pm on Sep 22, 2010 (gmt 0)

5+ Year Member

I just came across something that I believe worth commenting on here for others to see.

In HTML5, if you enter an image dimension as a percentage, it will not validate. The only reference I could find on the W3C site about image dimensions is this:

[w3.org ]

You will notice that it specifically states:

The dimension attributes are not intended to be used to stretch the image.

In some ways, that's fair enough but surely there are occassions where cross-platform image scaling may be appropriate? It was allowed in XHTML, so this seems to be a back-track on the part of the W3C.

Then again, there's a route out. CSS (at least CSS3 - not checked earlier versions) does allow percentage values for image dimensions.

So for anyone wanting to scale an image, ditch the HTML attribites and use CSS instead. Both HTML and CSS will validate.

Does this not render the clamp-down on HTML image scaling pointless?


5:53 pm on Sep 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

AIUI resizing an image via percentage scaling is seen as styling the image, so should be controlled via CSS, not HTML.

The <img>'s width and height attributes in HTML5 refer to the intrinsic dimensions of the image, and as you point out this is a change from previous (X)HTML specs which accepted n or n% for these attributes.

Does this change cause problems for you on your sites? May be worth raising with HTML-WG for discussion if it does.


9:07 pm on Sep 22, 2010 (gmt 0)

5+ Year Member

No, its not a problem mattur, I just happened to be experimenting with scalable images and came across this and thought it may be of interest.

W3Schools currently states that the percentage value is still ok, I've raised the issue in their forum.

Featured Threads

Hot Threads This Week

Hot Threads This Month