XHTML: What you need to know
by Marc Plotz
May 26, 2009
|
With everyone connecting in different ways your coding
practices could be causing heartache for your users. We'll
help you tackle this issue by showing what XHTML is and how
it can help you reach your maximum audience.
|
Introduction
There are many pages on the internet that contain HTML
that is either improperly formatted or just bad. These pages
will render OK in most browsers. However,
in certain situations they stand the chance of rendering
incorrectly. Compound this with the limited rendering power
of mobile and other hand-held devices and you stand a good
chance of presenting a broken page to a large audience. To
stop things like this from happening you can implement a good
coding standard along with a strong code foundation that
follows strict rules.
What is XHTML?
XHTML stands for eXtensible
Hypertext Markup Language. Put
simply, XHTML is HTML that implements the syntax
rules of XML. XHTML is stricter, cleaner,
and, in my own opinion, much more sensible than normal
HTML.
What's more, XHTML is not difficult to get used to at
all. Once you start applying the rules in your code you will
notice just how simple it is to present good markup. Lets
take a look at the implications.
The Groundwork
XHTML is built on a very solid foundation that requires
certain strict rules to be permanently enforced.
These rules are:
- Every page must have a Document Type Definition.
- Every page must have exactly one root element.
- All elements must always be typed out in lower
case.
- All elements must be properly nested.
- All elements must be closed.
- Attributes may not be minimized.
- The id attribute replaces the name
attribute.
Let us now look at these in more detail.
Every page must have a Document Type Definition.
There are generally three different dtd's that you can
use on your web pages:
- Strict: Use this DOCTYPE for clean, clear markup
and use it with CSS
- Transitional: Use this DOCTYPE when you are still
going to use some of HTML's presentational features along
with CSS
- Frameset: Use this DOCTYPE when you intend to use
frames on your site
Examples:
Strict:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict4.dtd">
Transitional:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Frameset:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
XHTML: What you need to know
Every page must have exactly one root element
|