Forum Moderators: open
Modern browsers make assumptions about your code, figuring it to be one of the "usual" standard types, like "HTML 4.0 Transitional" or "HTML 3.2 Final".
If you use a "document type definition" that is different from the "usual" bunch, then a DTD is essential to the proper rendering of your pages. i.e. what XML schema you are using, or where to find your customized DTD (Yes, you can write your own!).
You'll notice that attempting validate a page without a DTD results in the validator making an assumption about which DTD to use in order to attempt its validation.
In fact, the only code required for a "proper" HTML page is the <title> tag. But that's certainly a far cry from a "well-formed" HTML document, which should include at a minimum all of the "proper" tags, like the DTD, <html>, <head>, and <body> tags.
problem that was solved by removing it from the pages
The problem wasn't solved, you just made it harder to find by removing the DTD. It seems like the DTD you were using did not include instructions for how to handle some of the code you were using.
An illustration of the use of a modern XHTML DTD can be found here [validator.w3.org], at the World Wide Web Consortium [w3.org], which is the standards organization responsible for maintaining all of the "standard" DTDs.
When building new pages, it is best practice to use a full doctype in order to trigger the standards compliance mode, and validate your pages to avoid errors. This will help you create pages which are more compatible with newer technlogy and which display according to the declared standards.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
Next, run your pages through [validator.w3.org...] and fix all the errors found.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"> A shortened DOCTYPE such as that posted by g1smd has been used by quite a few over the years. If I recall, there were some bugs in various browsers when using a full DOCTYPE.
The suggestion to use a shortened DOCTYPE is deprecated in favor of using a full version which I've posted an example of above.
Shortened DOCTYPEs force IE into Quirks Mode. And, if you view the documentation for Mozilla, they have what is called Almost Standards Mode [mozilla.org] which occurs when using a shortened DOCTYPE.
The "half doctype"
Example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> This will trigger Quirks Mode. This doctype should only be used for editing or repairing legacy documents, as it allows you to validate more easily whilst not triggering standards mode.
Full doctypes (HTML 4.01 and XHTML 1.0 Transitional)
Examples:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> These will trigger Almost Standards Mode. The difference between this and full standards mode is very small, and to do with the handling of certain styles with
<table>s. In most cases, you will see no difference between this mode and the full standards mode. Full doctypes (HTML 4.01 Strict and XHTML 1.0 Strict)
Examples:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> These will trigger the full Standards Mode.
In short, if you are building a page using tables for layout (not for tabular data), then you may prefer one of the full but Transitional doctypes. In other cases, you can use either Strict of Transitional as required.
IE6 and Opera both have only two modes, so the full transitional doctypes trigger standards mode in both cases.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
These will trigger Almost Standards Mode. The difference between this and full standards mode is very small, and to do with the handling of certain styles with <table>s. In most cases, you will see no difference between this mode and the full standards mode.
Almost... :)
Though it's true that many of the differences between xhtml 1.0 and html 4.01 transitional doctypes and standards-mode doctypes have to do with tables, it would be more accurate to say that the transitional doctypes retain many (most?) of the presentational attributes used in earlier html versions. These include attributes used in tables such as 'valign', but also include 'bgcolor' (can be used on <body> element), 'align', etc. 'target' attributes are also still acceptable on links in both doctypes.
But you're right of course; the differences between transitional/strict are pretty small...
-B
the transitional doctypes retain many (most?) of the presentational attributes used in earlier html versions
Almost... ;) This is quite right, but that wasn't what I was referring to. The guide above is not talking about the differences between the DTDs themselves, merely the difference between the rendering modes in Mozilla/Firefox when encountering different doctypes.
As far as the browser is concerned, the actual DTD referenced in the doctype is irrelevant as the browser never reads or uses it: all browsers use their own custom DTD for rendering whatever the doctype, and the doctype switching merely affects the default display.