HighDots Forums  

<img width="100px" ...> valid (X)HTML?

HTML Writing HTML for the Web (comp.infosystems.www.authoring.html)


Discuss <img width="100px" ...> valid (X)HTML? in the HTML forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Christian Hackl
 
Posts: n/a

Default <img width="100px" ...> valid (X)HTML? - 12-17-2007 , 05:31 PM






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/....html#h-13.7.1
[2] http://www.w3.org/TR/html401/sgml/dtd.html#Pixels


--
Christian Hackl

Reply With Quote
  #2  
Old   
Harlan Messinger
 
Posts: n/a

Default Re: <img width="100px" ...> valid (X)HTML? - 12-17-2007 , 06:18 PM






Christian Hackl wrote:
Quote:
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.


Reply With Quote
  #3  
Old   
Michael Fesser
 
Posts: n/a

Default Re: <img width="100px" ...> valid (X)HTML? - 12-17-2007 , 06:22 PM



..oO(Christian Hackl)

Quote:
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 ...

Quote:
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


Reply With Quote
  #4  
Old   
Christian Hackl
 
Posts: n/a

Default Re: <img width="100px" ...> valid (X)HTML? - 12-18-2007 , 05:05 AM



Michael Fesser wrote:

Quote:
.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:

Quote:
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

Quote:
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


Reply With Quote
  #5  
Old   
Jukka K. Korpela
 
Posts: n/a

Default Re: <img width="100px" ...> valid (X)HTML? - 12-18-2007 , 05:29 AM



Scripsit Michael Fesser:

Quote:
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.

Quote:
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.

Quote:
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/



Reply With Quote
  #6  
Old   
Christian Hackl
 
Posts: n/a

Default Re: <img width="100px" ...> valid (X)HTML? - 12-18-2007 , 06:20 AM



Jukka K. Korpela schrieb:

Quote:
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.
No no, that's a misunderstanding. I thought the "img" issue was the
same, no matter whether HTML or XHTML was used. That's why I wrote
"(X)HTML". I just didn't want to make my posting unnecessarily long by
writing

<img src="img.png" alt="" width="100px" height="100px"> or <img
src="img.png" alt="" width="100px" height="100px" />

The question, in fact, arised in the context of XHTML

Quote:
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.
What about XHTML 1.1?

Are you telling me that there is no official (W3C) definition of what is
conforming XHTML 1.0?

In any case, I gained a lot of new insights from this thread, thank you all.


--
Christian Hackl


Reply With Quote
  #7  
Old   
Jukka K. Korpela
 
Posts: n/a

Default Re: <img width="100px" ...> valid (X)HTML? - 12-18-2007 , 11:50 AM



Scripsit Christian Hackl:

Quote:
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.

What about XHTML 1.1?
The situation is the same. On the other hand, XHTML 1.1 is an exercise
in futility. Even if you fake it to be text/html (there's an eternal
debate over the issue whether this is even "legal"), it won't work in
current web browsers, in general - there are some nasty requirements in
XHTML 1.1 especially as regards to image maps. It's based on the
modularization idea, which is rather uninteresting as such, but its
authors could not help throwing in some real changes, mostly poorly
documented (like adding syntactic restrictions in the DTD without
bothering to mention them in the part that purports to document the
changes).

Quote:
Are you telling me that there is no official (W3C) definition of what
is conforming XHTML 1.0?
No, I'm telling you that there is no normative _schema_. XHTML 1.0 is
defined in a quick and dirty way: the syntax is defined using a DTD (not
a schema), with some extra requirements written in prose, and with a
reference to HTML 4.01 as regards to any _meaning_ of the elements. This
leaves some issues open, so that there are different ways to write a
schema definition.

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



Reply With Quote
  #8  
Old   
Christian Hackl
 
Posts: n/a

Default Re: <img width="100px" ...> valid (X)HTML? - 12-18-2007 , 01:34 PM



Jukka K. Korpela ha scritto:

Quote:
Scripsit Christian Hackl:

Are you telling me that there is no official (W3C) definition of what
is conforming XHTML 1.0?

No, I'm telling you that there is no normative _schema_. XHTML 1.0 is
defined in a quick and dirty way: the syntax is defined using a DTD (not
a schema), with some extra requirements written in prose, and with a
reference to HTML 4.01 as regards to any _meaning_ of the elements. This
leaves some issues open, so that there are different ways to write a
schema definition.
OK, let's see if I got it...

There are some XHTML schemas published by the W3C, for example here:
http://www.w3.org/TR/xhtml1-schema/

However, those documents are just informal notes and are considered work
in progress, so they aren't exactly "official" schemas. Still, they are
good enough to be used by schema validators such as schneegans.de,
because they contain improvements such as concise formal definitions for
data types (which allows you, among other things, to formally define
that "width" and "height" must be integer values).

There is no official (normative) schema neither for XHTML 1.0 nor XHTML
1.1, there are just normative DTDs, which are unable to express
important requirements of the languages.

Is this correct?


--
Christian Hackl


Reply With Quote
  #9  
Old   
Jukka K. Korpela
 
Posts: n/a

Default Re: <img width="100px" ...> valid (X)HTML? - 12-18-2007 , 04:08 PM



Scripsit Christian Hackl:

Quote:
OK, let's see if I got it...
I think you did.

Quote:
There are some XHTML schemas published by the W3C, for example here:
http://www.w3.org/TR/xhtml1-schema/

However, those documents are just informal notes and are considered
work in progress, so they aren't exactly "official" schemas.
Right.

Quote:
Still,
they are good enough to be used by schema validators such as
schneegans.de, because they contain improvements such as concise
formal definitions for data types
That's useful if you use XHTML and you know the rules, so that you can
check whether the error messages identify real problems. The schema
validator's output cannot be authoritative, since the schema isn't, but
it can still be useful.

Quote:
(which allows you, among other
things, to formally define that "width" and "height" must be integer
values).
Well, such a requirement _can_ be expressed in a DTD, assuming it means
restricting them to unsigned integers and you use an SGML-based DTD. For
example, the HTML 4.01 DTDs restrict the ROWS and COLS attributes of a
TEXTAREA element that way. The XHTML 1.0 DTDs don't, since XML DTDs are
less expressive and cannot specify such a requirement. On the other
hand, even in HTML 4.01 DTDs, the WIDTH and HEIGHT attributes are
essentially unrestricted, since SGML DTDs cannot express the requirement
"must be an unsigned integer or an unsigned integer followed by the '%'
sign".

Quote:
There is no official (normative) schema neither for XHTML 1.0 nor
XHTML 1.1, there are just normative DTDs, which are unable to express
important requirements of the languages.

Is this correct?
Yes. I'd like to add that schemas, though more powerful, cannot
completely specify the languages, since they cannot express semantics
(meaning), and might have some limitations in the syntactic area as
well.

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



Reply With Quote
  #10  
Old   
André Gillibert
 
Posts: n/a

Default Re: <img width="100px" ...> valid (X)HTML? - 12-18-2007 , 04:54 PM



Jukka K. Korpela wrote:

Quote:
The situation is the same. On the other hand, XHTML 1.1 is an exercise
in futility. Even if you fake it to be text/html (there's an eternal
debate over the issue whether this is even "legal")
The W3C seems to endorse that practice, but common sense says as sending
something that's not HTML as text/html is a lie, leading to
interoperability problems.

This make me think of those baby games, where you've to put shapes in the
right holes.
http://store.babycenter.com/images/e...ture_image.jpg

Serving XHTML as text/html is like finding the cube (XHTML) "much
prettier" than the cylinder (HTML), but as there's no hole (in IE) for the
cube, striking with a hammer on the cube to make it fit in the cylinder
hole (text/html).
After having been crushed by a hammer, the cube isn't "pretty" anymore.

--
If you've a question that doesn't belong to Usenet, contact me at
<tabkanDELETETHISnaz at yahoDELETETHATo.fr>


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.