homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

HTML5 img element
Percentage dimension values not allowed

Msg#: 4205345 posted 4:14 pm on Sep 22, 2010 (gmt 0)

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?



WebmasterWorld Senior Member 10+ Year Member

Msg#: 4205345 posted 5:53 pm on Sep 22, 2010 (gmt 0)

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.


Msg#: 4205345 posted 9:07 pm on Sep 22, 2010 (gmt 0)

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved