Forum Moderators: open
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
or
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
so why is that?
and are these a must?
Thanks in advance
so why is that?
Because it's rendering in standards-compliance mode, which can change a lot of things. However, it is easier to code for standards mode and you get more reliable cross-browser rendering.
and are these a must?
I consider them so, for the reasons mentioned above (and a few others, such as validation).
It should also be noted that a single-line doctype like you show isn't correct. They should be split onto two lines, like shown here [w3.org]. As far as I know, using a doctype exactly in the way recommended by the W3C is the only way to get some browsers into full standards mode (I could be wrong on that).
I suggest you choose a doctype based on how strictly you want to write code, and stick with it, validating at least a few pages until you get used to it. You'll write cleaner, leaner, more cross-browser code, and those nice "Validated" pages are so pretty! ;)
It should also be noted that a single-line doctype like you show isn't correct. They should be split onto two lines, like shown here. As far as I know, using a doctype exactly in the way recommended by the W3C is the only way to get some browsers into full standards mode (I could be wrong on that).
I think you are wrong on that. The parser normalizes whitespace, so it makes absolutely no difference whether or not you split it over multiple lines.
However, it's correct to say that most if not all browsers use the presence of a DOCTYPE to select their rendering mode. Note that IE6 will revert to quirks mode if an xml prologue is present before the DOCTYPE.
It explains why you are having problems when you add the doctype.
a single-line doctype like you show isn't correct
In fact they are only shown like that to keep the page formatting straight on the w3.org site. ;) You can have your doctype on one or two lines (whatever you prefer). Just don't add arbitrary line-breaks except to replace spaces just to be safe.
added: beaten to it by asquithea ;)
Is that good?
That depends what you mean by "good". It means there are elements in your html that are already long gone from the W3C recommendations -- so you need to use an "antique" DTD to have it render properly. But the good news is that you still can get your page to display the way you want, at least for now.
I would suggest you keep reading and learning so after you learn more you can upgrade your mark-up to contemporary standards. You'll be very glad you did, I think, because all your web development will be smoother and faster once you gain this working knowledge.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> You should see that it doesn't break your layout and it is better than the ancient 3.2 doctype you have previously chosen. The next step after that is validation: head on over to the HTML validator [validator.w3.org] and see what errors and warnings come up. If there are a lot, work through them one by one from the top, and you'll usually find that later ones disappear as earlier errors are corrected.
Once you've got everything validated, then you can start looking at moving from quirks mode (which you get with the above doctype) to standards-compliance mode, which is more suitable for newer browsers.
If, on the other hand, you're open to new layout ideas, and are prepared to relinquish pixel-perfect page layout in return for elegance, beauty, and flexibility, then the CSS Zen Garden [csszengarden.com] is probably the canonical web-site.
For a more bleeding-edge-technique-oriented approach, and some more links, try css/edge [meyerweb.com].
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
Well that explains why it goes into quirks mode. The DocType has to be on the very first line in order to force IE6 into standards mode. Take the XML declaration out and all the browsers will behave with the same box model.