473,614 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<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"r eally 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 9857
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"r eally 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"r eally 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"r eally 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"r eally
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 misunderstandin g. 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"o r <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
interoperabilit y 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
<tabkanDELETETH ISnaz 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
10728
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 explaination for this? A co-worker told me it is not valid HTML. He may be right, but we both agree; it's odd that IE would handle it when the form is loaded, but not
22
2520
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
7839
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
13731
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> <div>
5
3056
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
2892
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 is not a null value. I am not using any code behind (C#) to bind the data or manipulate the data. I have read that when there is a null value in the database that there is no record in the "dataset". Can anyone show me how to bind a value in the...
0
8176
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8120
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8265
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8423
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7047
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
2560
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1705
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1420
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.