What You Should Already Know: HTML Tutorial
What You Should Already Know: HTML Tutorial
Before you continue you should have a basic understanding of the following:
If you want to study HTML first, please read our HTML tutorial.
What Is XHTML?
XHTML stands for EXtensible HyperText Markup Language
XHTML is almost identical to HTML 4.01
XHTML is a stricter and cleaner version of HTML
XHTML is HTML defined as an XML application
XHTML is a W3C Recommendation
Stay updated with the latest W3C recommendations in our W3C tutorial.
XHTML - Why?
« Previous Next Chapter »
XHTML consists of all the elements in HTML 4.01, combined with the strict syntax of
XML.
Why XHTML?
Many pages on the internet contain "bad" HTML.
The following HTML code will work just fine if you view it in a browser (even if it does
NOT follow the HTML rules):
<html>
<head>
<title>This is bad HTML</title>
<body>
<h1>Bad HTML
<p>This is a paragraph
</body>
In addition, you should start NOW to write your HTML code in lowercase letters, and NEVER skip
closing tags (like </p>).
In XHTML, all elements must be properly nested within each other, like this:
Note: A common mistake with nested lists, is to forget that the inside list must be within <li> and </li>
tags.
This is wrong:
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
<li>Milk</li>
</ul>
This is correct:
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
Notice that we have inserted a </li> tag after the </ul> tag in the "correct" code example.
This is wrong:
<p>This is a paragraph
<p>This is another paragraph
This is correct:
<p>This is a paragraph</p>
<p>This is another paragraph</p>
This is wrong:
A break: <br>
A horizontal rule: <hr>
An image: <img src="happy.gif" alt="Happy face">
This is correct:
This is wrong:
<BODY>
<P>This is a paragraph</P>
</BODY>
This is correct:
<body>
<p>This is a paragraph</p>
</body>
<html>
<head> ... </head>
<body> ... </body>
</html>
XHTML Syntax
<table WIDTH="100%">
This is correct:
<table width="100%">
This is correct:
<table width="100%">
<input checked>
<input readonly>
<input disabled>
<option selected>
<frame noresize>
This is correct:
Here is a list of the minimized attributes in HTML and how they should be written in XHTML:
HTML XHTML
compact compact="compact"
checked checked="checked"
declare declare="declare"
readonly readonly="readonly"
disabled disabled="disabled"
selected selected="selected"
defer defer="defer"
ismap ismap="ismap"
nohref nohref="nohref"
noshade noshade="noshade"
nowrap nowrap="nowrap"
multiple multiple="multiple"
noresize noresize="noresize"
<body>
</body>
</html>
Note: The DOCTYPE declaration is not a part of the XHTML document itself. It is not an XHTML
element. You will learn more about the XHTML DOCTYPE in the next chapter.
Note: The xmlns attribute in <html>, specifies the xml namespace for a document, and is required in
XHTML documents. However, the HTML validator at w3.org does not complain when the xmlns
attribute is missing. This is because the namespace "xmlns=http://www.w3.org/1999/xhtml" is default,
and will be added to the <html> tag even if you do not include it.
XHTML DTD
The most common DTD is XHTML Transitional.
<!DOCTYPE> Is Mandatory
An XHTML document consists of three main parts:
<!DOCTYPE ...>
<html>
<head>
<title>... </title>
</head>
<body> ... </body>
</html>
Note: The DOCTYPE declaration is always the first line in an XHTML document!
An XHTML Example
This is a simple (minimal) XHTML document:
<html>
<head>
<title>simple document</title>
</head>
<body>
<p>a simple paragraph</p>
</body>
</html>
The DOCTYPE declaration above defines the document type. The rest of the document looks like
HTML.
STRICT
TRANSITIONAL
FRAMESET
Use the transitional DOCTYPE when you want to still use HTML's presentational features.
Use the frameset DOCTYPE when you want to use HTML frames.
XHTML HowTo
To convert a Web site from HTML to XHTML, you should be familiar with the XHTML syntax rules
of the previous chapters. The following steps were executed (in the order listed below):
Tip: Your pages must have a DOCTYPE declaration if you want them to validate as correct XHTML.
We decided not to close the <img> tags with </img>, but with /> at the end of the tag. This was done
manually.
To make your XHTML compatible with today's browsers, you should add an extra space before the "/"
symbol.
A few more errors were found and edited manually. The most common error was missing </li> tags in
lists.
XHTML Validation
« Previous Next Chapter »
The Strict DTD includes elements and attributes that have not been deprecated or do not appear in
framesets:
The Frameset DTD includes everything in the transitional DTD plus frames as well:
http://w w w .w 3schools.com/xhtml/default.asp
XHTML Modularization
« Previous Next Chapter »
For some purposes XHTML is too large and complex, and for other purposes it's too simple.
By splitting XHTML into modules, the W3C (World Wide web Consortium) has created small and
well-defined sets of XHTML elements that can be used separately for small devices, or combined with
other XML standards in more complex applications.
XHTML Summary
This tutorial has taught you how to create stricter and cleaner HTML pages.
You have learned that all XHTML elements must be properly nested, XHTML
documents must be well-formed, all tag names must be in lowercase, and that all
XHTML elements must be closed.
You have also learned that all XHTML documents must have a DOCTYPE declaration,
and that the html, head, title, and body elements must be present.
CSS
CSS is used to control the style and layout of multiple Web pages all at once.
With CSS, all formatting can be removed from the HTML document and stored in a
separate file.
CSS gives you total control of the layout, without messing up the document content.
To learn how to create style sheets, please visit our CSS tutorial.
JavaScript
A static web site is nice when you just want to show flat content, but a dynamic web site
can react to events and allow user interaction.
JavaScript is the most popular scripting language on the internet and it works with all
major browsers.
If you want to learn more about JavaScript, please visit our JavaScript tutorial.