473,383 Members | 1,805 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,383 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 9837
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.