473,289 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

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

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
Dec 17 '07 #1
7 9831
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.
Dec 18 '07 #2
..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
Dec 18 '07 #3
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
Dec 18 '07 #4
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/

Dec 18 '07 #5
Jukka K. Korpela schrieb:
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 :)
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
Dec 18 '07 #6
Jukka K. Korpela wrote:
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>
Dec 18 '07 #7
Jukka K. Korpela scrisse:
Scripsit Christian Hackl:
>(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. [...]
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".
Oh, so the only reason the DTD does not restrict width/height to integer
values is that pesky possibility of specifiying percentages?
Interesting! It's always amazing for me to see how little I really know
about all that stuff.

Still, though, I wonder why the W3C would not just declare those
informative schemas authoritative and incorporate them into the official
validation service, but then again, what do I know about the wondrous
ways of the W3C? :)
--
Christian Hackl
Dec 18 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John MacIntyre | last post by:
Hi, Using the script below, when you click on the radio button beside click here .... the first row shrinks. Has anybody else ever experienced this? Does anybody know of a logical...
22
by: David. E. Goble | last post by:
Hi All; I have a few of these; sigsImages="sigs/finished1.jpg" sigsImages="sigs/foghorn.jpg" lower I have;
6
by: Rolf Welskes | last post by:
Hello, if I have for example: <table style="width: 100%; height: 100%;" border="1"> <tr> <td style="width: 100px">k </td> <td style="width: 100px">k </td> </tr>
4
by: Francesco Moi | last post by:
Hi. I'm trying to place three "<div class=foo>" boxes in the same line: ----html-------------------- <HTML><HEAD> <link href="test.css" rel="stylesheet" type="text/css" /> </HEAD> <body>...
5
by: Jean Pierre Daviau | last post by:
Hi to every one. How can I manage to write this kind of css in a style="". img { width: 150 px; height: 100 px; text-align: center; }
4
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.