HTML Cookbook Basic HTML Course

It's Easy!

Alternate version

DTD's, Namespace and Character Set

For a page to validate, you need to have a DTD (Document Type Declaration) at the very top of your page, right before <html>.

Simple put, the Document Type Statement tells validators and browsers which version of HTML you are using for your page so they know which set up of rules to use to interpret your page.

Here is the DTD for XHTML Transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


Next, we need to define a namespace in XML. This makes HTML work in XML, giving us XHTML. That's a mouthful, huh?

Namespace is just an attribute for <html>

Once we create an XML namespace, we really should state the language our page is written in (English or "en") for both XML and the web.

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


Finally, we need to add a "character set META tag" in the <head> so your characters are shown correctly. For example, if you use the dollar sign, you want to show dollars, not yen or pounds.

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<head>

For your convenience, here are links to pages with copy-and-paste code that includes all of these:
DTD's for HTML
DTD's for XHTML

Happy coding!
Gnubee

Links
Tips
Tools
References
Rules
HTML Help Gnubee - Newsgroup
HTML Course Contents (Home)

Valid XHTML 1.0!

Valid CSS!