Click here to get back home

valid (X)HTML?

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
valid (X)HTML? Christian Hackl 12-17-2007
|--> Re: valid (X)HTML? Harlan Messinge...12-17-2007
  |--> Re: valid (X)HTML? Christian Hackl12-18-2007
  |--> Re: valid (X)HTML? Jukka K. Korpel...12-18-2007
  ---> Re: valid (X)HTML? Christian Hackl12-18-2007
    ---> Re: valid (X)HTML? Jukka K. Korpel...12-18-2007
      ---> Re: valid (X)HTML? Christian Hackl12-18-2007
      | ---> Re: valid (X)HTML? Jukka K. Korpel...12-18-2007
      |   `--> Re: valid (X)HTML? Christian Hackl12-18-2007
      `--> Re: valid (X)HTML? André Gillibert12-18-2007
Posted by Christian Hackl on December 17, 2007, 6:31 pm
Please log in for more thread options
Hi everyone,

I've got a question about what makes the "img" element's width/height
attributes valid HTML or XHTML.

First of all, this is a rather theoretical question, but digging through
the W3C HTML 4.01 standard and this group's archive didn't give me a
satisfactory answer, so here we go:

Is <img src="img.png" alt="" width="100px" height="100px"> really valid?

That kind of width/height specification is certainly accepted by the W3C
validator (no matter which version of HTML or XHTML you use), but to my
surprise, I found out that the validator accepts virtually everything
for the width/height attributes, even negative and non-numeric values,
for example:

<img src="img.png" alt="" width="-100" height="fifty">

According to [1], width/height are of type "length", which is either a
percentage ("50%" is explicitly stated as an example) or "%Pixel" [2].
There it says that a pixel value is an "integer representing length in
pixels".

So if the standard requires an integer value for width/height, why does
the validator accept non-integer values? And why doesn't the standard
require unsigned integers?


[1] http://www.w3.org/TR/html401/struct/objects.html#h-13.7.1
[2] http://www.w3.org/TR/html401/sgml/dtd.html#Pixels


--
Christian Hackl

Posted by Harlan Messinger on December 17, 2007, 7:18 pm
Please log in for more thread options
Christian Hackl wrote:
> Hi everyone,
>
> I've got a question about what makes the "img" element's width/height
> attributes valid HTML or XHTML.
>
> First of all, this is a rather theoretical question, but digging through
> the W3C HTML 4.01 standard and this group's archive didn't give me a
> satisfactory answer, so here we go:
>
> Is <img src="img.png" alt="" width="100px" height="100px"> really valid?
>
> That kind of width/height specification is certainly accepted by the W3C
> validator (no matter which version of HTML or XHTML you use), but to my
> surprise, I found out that the validator accepts virtually everything
> for the width/height attributes, even negative and non-numeric values,
> for example:
>
> <img src="img.png" alt="" width="-100" height="fifty">
>
> According to [1], width/height are of type "length", which is either a
> percentage ("50%" is explicitly stated as an example) or "%Pixel" [2].
> There it says that a pixel value is an "integer representing length in
> pixels".
>
> So if the standard requires an integer value for width/height, why does
> the validator accept non-integer values? And why doesn't the standard
> require unsigned integers?

I'm sure others will explain this in more detail, but the summary is
that validity is only a subset of compliance.

Posted by Michael Fesser on December 17, 2007, 7:22 pm
Please log in for more thread options
.oO(Christian Hackl)

>I've got a question about what makes the "img" element's width/height
>attributes valid HTML or XHTML.
>
>First of all, this is a rather theoretical question, but digging through
>the W3C HTML 4.01 standard and this group's archive didn't give me a
>satisfactory answer, so here we go:
>
>Is <img src="img.png" alt="" width="100px" height="100px"> really valid?

No, but ...

>That kind of width/height specification is certainly accepted by the W3C
>validator (no matter which version of HTML or XHTML you use), but to my
>surprise, I found out that the validator accepts virtually everything
>for the width/height attributes, even negative and non-numeric values,
>for example:
>
><img src="img.png" alt="" width="-100" height="fifty">

... an SGML validator like the W3 validator cannot check attribute
values. A schema validator can, which is what you should use to validate
XML/XHTML.

Micha

Posted by Christian Hackl on December 18, 2007, 6:05 am
Please log in for more thread options
Michael Fesser wrote:

> .oO(Christian Hackl)
>>
>> Is <img src="img.png" alt="" width="100px" height="100px"> really valid?
>
> ... an SGML validator like the W3 validator cannot check attribute
> values.

Thanks! That actually makes sense. I've just found out that there's even
a chapter in the HTML 4.01 standard that explains this problem:

| Specifically, an SGML parser ensures that the syntax, the structure,
| the list of elements, and their attributes are valid. But for
| instance, it cannot catch errors such as setting the width attribute
| of an IMG element to an invalid value (i.e., "foo" or "12.5").
| Although the specification restricts the value for this attribute to
| an "integer representing a length in pixels," the DTD only defines it
| to be CDATA, which actually allows any value. Only a specialized
| program could capture the complete specification of HTML 4.

http://www.w3.org/TR/html4/sgml/intro.html

> A schema validator can, which is what you should use to validate
> XML/XHTML.

Do you recommend any specific schema validator?

Googling for "schema validator xhtml" revealed this tool:
http://schneegans.de/sv/

It catches the width/height errors. Looks pretty good to me.


--
Christian Hackl

Posted by Jukka K. Korpela on December 18, 2007, 6:29 am
Please log in for more thread options
Scripsit Michael Fesser:

>> Is <img src="img.png" alt="" width="100px" height="100px"> really
>> valid?
>
> No, but ...

Yes it is. It is valid but incorrect (by the specifications). In
practical terms, browsers tend to ignore the "px" part, but that's a
different issue.

>> <img src="img.png" alt="" width="-100" height="fifty">
>
> ... an SGML validator like the W3 validator cannot check attribute
> values.

Yes it can and it does (and the W3C validator is actually a mixed SGML
and XML validator, with all the usual consequences of a compromise). In
this case, it checks against the attribute declaration, which is CDATA,
which means pretty much anything, including all the cases mentioned
here.

> A schema validator can, which is what you should use to
> validate XML/XHTML.

A schema validator, using suitable schema, can check much more than a
DTD validator, for sure. However, this is about XML (including XHTML),
and we can see from the lack of the magic "/" that the OP is using
classic, nominally SGML based HTML.

Moreover, there is no normative schema for XHML 1.0. The schemas are
just unofficial attempts at capturing the syntax requirements (partly
formal, partly prose) in the XHTML 1.0 specification.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/


Similar ThreadsPosted
problems getting valid HTML out of PHP September 17, 2004, 6:26 pm
This page is not a valid HTML 4.01.WHY? October 26, 2004, 2:44 pm
valid html for framesets February 13, 2005, 10:25 am
Valid HTML Tutorial December 6, 2005, 12:12 pm
Unrecognized file format prolem with valid html, please help! November 9, 2004, 6:55 pm
Seemingly-simple valid HTML renders diff in FF1.0, IE6 January 25, 2005, 12:04 pm
W3C Validator error?
is valid for doctype HTML 4.01 Strict
April 21, 2005, 12:46 pm
Valid XHTML June 13, 2007, 7:10 pm
Name attribute not XHTML valid April 7, 2005, 2:48 pm
valid code with flash September 2, 2005, 6:29 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap