Monday, September 13, 2010

Web standards and XHTML

As mentioned earlier, we’ll be working with Extensible HyperText Markup Language
(XHTML) rules in this book, rather than HTML. The differences between HTML and XHTML
are few, but important, and largely came about because of the inconsistent way that
browsers displayed HTML. XHTML is stricter than HTML and has additional rules; oddly,
this actually makes it easier to learn, because you don’t have to worry about things like
which case to use for tags and whether they require closing. You have hard-and-fast rules
in each case. XHTML-specific rules are as follows.
All tags and attribute names must be in lowercase and must always be closed. Therefore,
the following is incorrect:
This is a paragraph.

This is another paragraph.
The preceding lines should be written like this:

This is a paragraph.
This is another paragraph.
Unlike HTML, all XHTML elements require an end tag, including empty elements (such as
br, img, and hr). The HTML for a carriage return is br. In XHTML, this must be written


or, more usually, in a combination form that looks like this:
. The trailing
slash is placed at the end of the start tag, with a space prior to it (now typical practice, this
was initially done to ensure compatibility with aging browsers that would otherwise ignore
the tag entirely if the space wasn’t present).
Tags often have attributes that modify them in some way. For instance, two attributes for
the table cell tag td are nowrap (to stop content wrapping) and colspan (which states how
many columns this cell should span). In XHTML, attributes must be quoted and always
have a value. If necessary, the attribute name itself is repeated for the value. Therefore, the
following is incorrect:

Instead, in XHTML, we write this:

Evolution is another aspect that we have to deal with. Just as the survival of the fittest
removes some species from nature, so too are tags (and attributes) unceremoniously
dumped from the W3C specifications. Such tags and attributes are referred to as
deprecated, meaning they are marked for removal from the standard and may not be supported
in future browsers. In cases when deprecated tags are used in this book, this will be
highlighted (and likewise in the reference section); in most cases, these tags can be
avoided.

No comments:

Post a Comment