Forum Moderators: open
so my question is, should i take the HTML 4.0 or 4.01 declaration?
what are the (dis)advantages?
it doens't matter if spiders would like the one or the other way better
since the documents are error pages.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
If you omit that part, then you could just as well leave the declaration away altogether, as most browsers will then switch to "quirks mode", and display the page in whatever ways they please.
I'm confused as well. A page will validate without the URI.
That's because bird was incorrect. The system identifier (the part that's a URI) is optional in an SGML declaration when the external identifier indicates the language is "PUBLIC" (as HTML's formal public identifier does with the word "PUBLIC").
(The system identifier can, in fact, be changed by the document author to point to any location containing a copy of the DTD for the SGML language used.)
The SGML declaration used by Apache is a valid declaration for HTML 2.0 as defined by RFC 1866. It even appears in the examples there.
That t-online public identifier is shadier. I think it's valid as a "public identifier", but it's definitely not valid as a "formal public identifier" (it doesn't identify the owner or public language of the DTD), which could make things difficult for a real SGML parser.
bird is (unfortunately) correct when pointing out that browsers will render pages differently if they've changed or omitted the system identifier. That was just a damn stupid decision on Microsoft's part, but we're stuck with it. If you don't like quirks mode, you need to include the system identifier.
I'm confused as well. A page will validate without the URI.
The reason the URI is there is because, according to the W3C, it "allows user agents to download the DTD and any entity sets that are needed ..." They are not required for validation.
The first part of a DOCTYPE is the DTD Name:
<!DOCTYPE html [b]PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"[/b] and is used by a validator to tell it what DTD to use to do it's job. An HTML validator will have DTD name as part of it's own catalog, so it doesn't need the URI to look up the rules -- it already knows them.
However, if a "user agent" or validator doesn't have the DTD Name in it's catalog, that's where the DTD Location comes in. This is the second part of the DOCTYPE:
[b]"http://www.w3.org/TR/html4/loose.dtd">[/b] and it is a URI that tells the validator where to look to get the rules that the document is supposed to conform to.
So, all a validator does is look at a set of rules, look at your document to see if it obeys those rules, and then nag at you if your document doesn't.
Most of the better validators know the PUBLIC rules (standards) by their name, but sometimes they don't, and so they have to go and look it up on the internet. The DTD Location gives them the means to do so. But it isn't required for validation.
Of course, that whole "modes" thing with the browsers is what confuses the issue: basically, a doctype without a URI is will throw a browser into "quirks" mode, so you might not get the result you expect if you leave the URI out. So while technically it is not required to have the URI there, if you don't have it you might as well not have a DOCTYPE at all as far as these particular "user agents" are concerned.
Some references:
[htmlhelp.com...]
[alistapart.com...]
[xmlwriter.net...]
Someone please correct me if I am wrong. :)
Guilty as charged! ;)
However, my conclusion still stands, as confirmed by moonbiter:
So while technically it is not required to have the URI there, if you don't have it you might as well not have a DOCTYPE at all as far as these particular "user agents" are concerned.
Understanding what this means, I can only reccommend: Never use a doctype declaration without including the DTD URI, or face the prospect of being confronted with highly inconsistent browser behaviour.
Unfortunately, the URI can interfere with CSS. I had the experience and Brett made a suggestion to drop the URI, which I did and it corrected the issue with the CSS and Absolute Positioning. If you look at the source code for the forums, you'll see that the URI is also absent.
I haven't seen any Quirks without the URI and I've been using it that way for at least 6 months on a new site and longer with older sites.
> If you omit that part, then you could just as well leave the declaration away altogether.
Can't omit the DOCTYPE if you want to validate, its got to be there if I'm not mistaken.
Can't omit the DOCTYPE if you want to validate, its got to be there if I'm not mistaken.
Note that you can have perfectly well-formed HTML without it being valid. With the W3C's HTML Validation Service [validator.w3.org] you can validate your HTML without a DOCTYPE by specifying a document type during the input process. You'll get a big yellow warning box saying how horrible you are for not having a valid DOCTYPE, but then it will go on and validate your page for you. ;)
So, if a page isn't valid, is a doctype a plus or a minus or neither?
If you are using elements/attributes from versions of HTML older than 4, but are otherwise have well-formed markup, then use the DOCTYPES for those versions:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
Your example, background, is a real attribute in HTML 4.01 (even if it is a deprecated) and would be valid according to the transitional DOCTYPE:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
If you are using proprietary IE or Netscape attributes and elements (like blink and marquee, for which you should be crucified ;)) then I wouldn't put a doctype in. Sure, there are doctypes for some of these, and the W3C validation service even recognizes some of them (see [validator.w3.org...] but what's the point, really.
Validation is not a moral issue -- you are not bad or evil if the markup you write is invalid. It is simply a way to ensure that you write clean markup, troubleshoot problems, and provide forward compatability. All IMHO, YMMV. :)
p.s., if you really want to have your nonstandard code validate, you could create your own DTD:
[htmlhelp.com...]
But again, what's the point of that?
<!DOCTYPE> + URI = good form. Use it as your foundation as you build and you will not have to worry about quirk mode or standards mode.
Tell that to Opera! ;)
With the URI, there was a spacing problem at the tops of pages. Without it, the spacing problem was gone. Haven't tested it since then which was a couple of months ago.
I might just give it a try to see if the bug has been corrected. All other browsers displayed the pages properly with the URI except for Opera.
By accepting "quirks mode" you are never really "seeing" HTML elements as intended. When you include the URI (as you build) you simply (very simply!) create your styles to present your page elements as desired.
I might just give it a try to see if the bug has been corrected. All other browsers displayed the pages properly with the URI except for Opera.
It is definately NOT a bug. Opera is strict where others are lax.
HTML automatically adds an extra blank line before and after a heading.
Headings for example: Opera will include a spacing at the beginning (top) as well as the end (bottom) of headings.
h1,h2 {margin-top:0;} will allow headings to render the same in Opera as they do in IE.
What was happening is the URI was causing a 12px gap between the top of the page and the beginning of the <div> that contains the navigation include. That <div> is set to left:0px; and top:0px;
All the other browsers we tested in when the URI was present worked fine. When viewing in Opera, the gap appeared. Brett replied to a topic I had posted in discussing the issue. I can't recall the exact response but the fix was to eliminate the URI which eliminated the problem.
Once again, Opera is correct in this. Others use body {margin:0;} (incorrectly), you may want to try it by adding body {padding:0;} and then set your divs.
You can safely use the following:
body {
margin:0;
padding:0;
}
Agreed!
Just added the URI and hadn't even had a chance to view in Opera when I saw a problem in Moz. I'm using...
Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530
I have a set of <div>'s that contain a remote rollover effect within the navigation structure. By remote, I mean there is a third image involved with the rollover state. That set of <div>'s ended up moving down by about 5px or so and appeared to be partially behind another image. Hard to explain, but there is an issue.
The <div>'s are absolutely positioned and there are no other unusual declarations. They typically look like this...
div.globe{position:absolute;left:148px;top:0px;width:183px;height:183px;}
Yes, I know, shorthand, shorthand! Haven't had the time to really hunker down and tackle that one yet. So, where could my problem be now? I did add the padding:0px; to the body rule as suggested. I'll leave that there for Opera. Now what?
So I'm back to the short doctype for now. I see many sites that use the shortened version and I can only guess they use it due to various issues like these.
there is a third image involved...
img.myStyle {display:block;} or inline? Don't forget that if you are using images that have not been politely instructed to behave as block elements, they will be subject to all the niceties assigned to inline text. There are instances where this could cause display issues. Try adding a 1px solid black border to your div and look for any distortion that the image(s) may produce.
Once again, Opera is correct in this. Others use body {margin:0;} (incorrectly), you may want to try it by adding body {padding:0;} and then set your divs
Note that this is not strictly true. Opera just chooses to make the default indentation of text from the edge of the viewport the body element padding. Mozilla and MSIE choose to make the default indentation of text from the edge of the viewport the body element margin.
Both are correct implementations, however, because the outermost element of the viewport is not the body element but the root element of the document -- in the case of web pages the html element.
This can be easily demonstrated by placing a border on the body element and playing around with the padding and the margins of the element.
So, as papabaer suggests, be certain to specify both body {margin: 0px; padding: 0px} to zero out your margins.