Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

70 users online



[Article] kiswa's Article Part 2: DOCTYPE

[Article] kiswa's Article Part 2: DOCTYPE

Currently viewing this thread: 1 (0 members and 1 guests)


Page 1 out of 2
kiswa

kiswa

Yeah, kiswa.
Status: Offline!

[Article] kiswa's Article Part 2: DOCTYPE

Using DOCTYPE Matters!

First, let??s refer back to the ??semantic?? markup I had in Part 1:

Code:

<html>
<head>
<title>Test</title>
</head>

<body>

<div id="header">
<h1>This is the Page Title</h1>
</div>

<div id="nav">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>

<div id="main_text">
<h3>Paragraph Title</h3>
<p>This is some filler text... This is some filler text... This is some filler text...
<br />This is some filler text... </p>
<h3>Paragraph Title</h3>
<p>This is some filler text... This is some filler text... This is some filler text...
<br />This is some filler text... </p>
</div>

<div id="footer">
<p>Copyright 2005 All Rights Reserved.</p>
</div>

</body>
</html>

Okay, so I mentioned before that this isn??t really semantic code. It??s semantic, but it includes extras - markup beyond the basics required for display on a text-only medium. The Internet is not text-only though, now is it? So, I??ve included all the divisions to make styling this document with CSS much easier for us to accomplish!

There is however, something this document is missing and that is?

The All Important DOCTYPE!

The DOCTYPE should be the very first thing in your document and gives a validator the information it needs to check your document??s syntax, and lets a browser know what to expect. There are a few options available to you:

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!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 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

If you??re going to use frames, the DOCTYPE for the frameset page should be one of the following:

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

There are also a few options that aren??t used as much, and they are:

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

The first group has the most common choices used, namely HTML 4 (Strict and Transitional), and XHTML 1.0 (Strict and Transitional again!). The Strict versions emphasize ??structure over presentation. Deprecated elements and attributes [sic], frames, and link targets are not allowed [sic].? The usefulness of Strict mode is that it focuses on structure and is more easily adaptable to varying browsing options. The Transitional versions allow you to include non-presentational code so you can compensate for media that do not support CSS styling like they should.

The XHTML standard is really an XML version of the HTML 4 standard (and because of this it allows for even further separation of content from style, but that??s a whole other set of articles and I??m not going to go there). The biggest difference between the two is that XHTML has no unclosed tags (i.e. <img src=?? alt=??> is no good, it??s <img src=?? alt=?? /> in XHTML).

The second group is for Framesets. If you??re going to use frames, use the appropriate DOCTYPE! The Frameset DOCTYPEs above are variants of HTML 4 Transitional.

The last group includes DOCTYPEs for older HTML standards. While they are supported by almost every browser you could think of, they don??t support CSS very well and are entirely incompatible with Framesets and internationalization (and 2.0 doesn??t even do tables well).

Setting a DOCTYPE tells the browsers that visit this page what to expect and gives us a standard to validate our code against. And that??s where DOCTYPE becomes really useful!

Validate Your Code!

Okay, lets say we want to use XHTML 1.0 Strict. Thanks to DOCTYPE, we can be sure that everything treats our code as XHTML 1.0 Strict. And online validators like http://validator.w3.org/ will know what to compare our code to so we can see how we??ve done. Simply by adding the DOCTYPE to the beginning of our code, we get a ??Tentative? validation from that address. The only thing missing for a guaranteed validation is a character set (a.k.a. charset).

If we simply add one little meta tag, we have a valid XHTML 1.0 Strict document. That meta tag is:

Code:

<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" />

That sets our character set to iso-8859-1 (International Standards Organization Latin 1 charset). There are other options, but if your site is going to be using the standard Latin 1 characters, use that charset. For more options, you can go here.

The content type is also set in this meta tag, and in the case of XHTML 1.0 Strict, it is "application/xhtml+xml". You can find out more about which content type to select by going here.

So, our final code for our Standards Compliant, Valid, XHTML 1.0 Strict document is:

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" />
</head>

<body>

<div id="header">
<h1>This is the Page Title</h1>
</div>

<div id="nav">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>

<div id="main_text">
<h3>Paragraph Title</h3>
<p>This is some filler text... This is some filler text... This is some filler text...
<br />This is some filler text... </p>
<h3>Paragraph Title</h3>
<p>This is some filler text... This is some filler text... This is some filler text...
<br />This is some filler text... </p>
</div>

<div id="footer">
<p>Copyright 2005 All Rights Reserved.</p>
</div>

</body>
</html>

I was going to go into methods of using CSS to style a document like this (actually, I was going to use this one!), but it seems my DOCTYPE article got nice and long so?.

Next Time - kiswa's Article Part 3: Styling With CSS

Thanks,
kiswa

Source:
http://htmlhelp.com/tools/validator/doctype.html

___________________

www.kiswa.com
My attempt at articles for Neverside CodeBase: Part 1 Part 2 Part 3
(. )v( ) <- The Webstandards Owl

Last edited by kiswa, May 26th, 2005 02:49 PM (Edited 1 times)

Locke

Locke

"Refocusing" My Time
Status: Offline!

Excellent article Kiswa, keep up the awesome work. Hopefully this will inspire others also! Not to mention this will give us some beginner content to work with for releasing so it doesn't look all blank.

___________________

The Audoptic Weblog. It's where the magic happens.

kiswa

kiswa

Yeah, kiswa.
Status: Offline!

Glad you like it! I'll try to do article three tomorrow. I think that'll be it though.

Unless someone can give me something else in this topic to discuss. I'm not an expert by any means, but I'm willing to give it a try.

___________________

www.kiswa.com
My attempt at articles for Neverside CodeBase: Part 1 Part 2 Part 3
(. )v( ) <- The Webstandards Owl

army

army

Neverside Peacekeeping Forces
Status: Offline!

kiswa: i think you should add extra notes that inline frame are deprecated and cannot be used even in frameset doctype (i found alot of people including myself misunderstood this)
just a suggestion tho

___________________

"The only thing i hate about Sunday is that because tomorrow is Monday"
army

Rabbitlab

Rabbitlab

dotcom
Status: Offline!

Kiswa, little question: Some authors claim that when using xhtml, you should send out content="application/xhtml+xml" instead of text/html. Now on one hand, they have a point because it is xhtml but on the other hand it's text and not an application.

Anyway, maybe it would be good to explain it in your article, since other people might have the same question.

___________________

Blog / Lab

Simon

Simon

Jag är Gandalf den grå och den vite, men vem är du?
Status: Offline!
Originally posted by Rabbitlab:

Kiswa, little question: Some authors claim that when using xhtml, you should send out content="application/xhtml+xml" instead of text/html. Now on one hand, they have a point because it is xhtml but on the other hand it's text and not an application.

Anyway, maybe it would be good to explain it in your article, since other people might have the same question.

I think you talk about XHTML 1.1 now.

___________________

Neversidian, your staff is broken.

Rabbitlab

Rabbitlab

dotcom
Status: Offline!

Nope, ALL types of xhtml: http://keystonewebsites.com/articles/mime_type.php

___________________

Blog / Lab

mroak

mroak

Swede
Status: Offline!

great article! can't wait for part 3 Wink

___________________

//mr.oak

Simon

Simon

Jag är Gandalf den grå och den vite, men vem är du?
Status: Offline!

Hmm, I think you're correct rabbit. http://www.w3.org/TR/xhtml-media-types/

___________________

Neversidian, your staff is broken.

Rabbitlab

Rabbitlab

dotcom
Status: Offline!

text/html may be used with xhtml 1.0 but must not be used with xhtml 1.1. And using application/xhtml-xml with 1.1 (or 1.0, which is possible) is apparently useless since some browsers do not support it yet.

So does that mean xhtml 1.1 is useless for "normal" webuse at the moment?

___________________

Blog / Lab

Page 1 out of 2
Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0207 seconds.