Re: Image width specification in html5

2011-11-20 15:55, David Swindlehurst wrote:

> The W3C Validator for html5 (as with previous versions) accepts element
> widths specified in percentages,

Markup validation for any previous version of HTML does not check the 
width attribute value at all, as it is declared as having CDATA value. 
So width="50%" is accepted for the same reason as width="~.$x§1!" is.

The "W3C Validator for html5" is really the informal HTML5 linter at 
http://validator.nu embedded into the user interface of the W3C Markup 
Validator.

> through CSS,

I'm not sure what you mean by that. The width attribute is not about CSS 
at all but about HTML constructs that have effects similar to some CSS 
constructs. And in HTML5, that attribute is currently allowed to authors 
only for the following elements: canvas; embed; iframe; img; input; 
object; video. And only with a non-negative integer as the value. 
"Obsolete features" (features that browsers "must" support but authors 
"must not" use) include width for several other elements as well, but 
the use of an "obsolete feature" is treated as an "error" by the "W3C 
Validator for html5".

If you mean using CSS to set some width in an HTML document, then that's 
external to HTML and not checked by the "W3C Validator for html5".

> which enables accurate
> page rendering for any size of display.

I wonder what that means, but I understand that percentage widths can be 
used to scale an image according to available width. The accuracy of 
such scaling is a quality of implementation issue. And the scaling is 
possible in CSS.

Disallowing width="25%" is consistent with the general idea that styling 
be delegated to CSS instead of being done in HTML. It's comparable to 
disallowing the <font> element, though one might argue that image 
scaling is not really stylistic.

But there's a difference that I didn't realize before this. HTML5 
forbids, for example, the <font> element, but it requires browsers to 
keep supporting it. It seems that there is nothing similar for 
percentage widths.

> EXCEPT that it refuses to accept
> percentages for specifying width for the img tag! For instance
>
> <div class="?"><img src="image.png" alt="ancient grey-haired awkward
> person" width="25%" /></div>
>
> results in an error - the Validator expects an absolute number (of
> pixels!).

Such a report is compatible with the current HTML5 draft.

> Does the Spec need
> revising, or is the Validator wrong in expecting an absolute number?

It seems that the HTML5 drafts do not impose any requirements on user 
agents regarding percentage values for the width attribute. Thus, an 
implementor would treat them as errors, probably ignoring the entire 
attribute. This would create harmful conflict in browser behavior, as 
existing browsers generally support such values.

Or am I missing something? User agent requirements (regarding dimension 
attributes)
do not say anything about values not mentioned in author requirements:
http://www.w3.org/TR/html5/the-map-element.html#"ttr-dim-width

That part of the draft also implicitly gives a reason for allowing 
pixels only: "The dimension attributes are not intended to be used to 
stretch the image."

By the way, it occurred to me that constructs like width="25px" are not 
uncommon on web pages and are generally processed by browsers as if the 
attribute were width="25". That is, anything after the unsigned integer 
is just discarded, unless it happens to be the percent sign "%". I 
cannot find a description of such behavior in the HTML5 draft. Shouldn't 
this common idiom, or mistake, be recognized and documented as a 
requirement on user agents?

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

Received on Monday, 21 November 2011 08:48:29 UTC