XHTML
- XHTML (Extensible HyperText Markup
Language)
- Backwards compatible with HTML
Case sensitivity
Comments
<!-- Multiple-line
comment -->
- Avoid putting "--" or ">" inside a comment, as this is not
supported by some web browsers.
Differences from HTML
CDATA sections
- CDATA section is required for any text containing
<
or &
- If possible, put all CSS and JavaScript
in separate files (otherwise, if there's any occurrence of
<,
&,
or --, have to wrap the contents in a CDATA section)
<script type="text/javascript">
// <![CDATA[
...
// ]]>
</script>
Well-formed XML
- XHTML documents must be well-formed
- XHTML elements must be properly nested
- Tag names must be in lowercase
- All XHTML elements must be closed (this
does not apply to the
DOCTYPE declaration)
<p>...</p>
- Empty elements must either have an end
tag or the start
tag must end with /> (with a blank space preceding the forward
slash, for compatibility with older browsers).
<br />
<hr />
<img src="logo.png" alt="Logo" />
<p />
- Attribute names must be in lower case
- Attribute values must be quoted
- Attribute minimization is forbidden (for instance, use
<input disabled="disabled" /> instead of <input
disabled>)
Misc
- The only predefined named entities
supported are:
< > &
" '
- The id attribute replaces the name
attribute
- If you use the lang attribute in an
element, you must also
use
the xml:lang attribute with the same value.
<div lang="no" xml:lang="no">Text</div>
- The XHTML DTD defines mandatory elements
- The attribute
xmlns="http://www.w3.org/1999/xhtml" can be
omitted from the <html> tag (as that value is used
by default).
DOCTYPE
- The XHTML DTD (Document Type Definition)
must be specified in
the DOCTYPE declaration
- The DOCTYPE declaration must be on
the first line of the
XHMTL file.
- The DOCTYPE declaration is only used
for validating a
page;
web browsers don't use it.
XHTML 1.0 Strict
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- Use HTML for data, CSS for
presentation
- IE6+: Almost Standards mode
- FF, Safari, Opera: Standards mode
XHTML 1.0 Transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- Use HTML for data and presentation
- Useful for supporting web browsers
that don't understand
CSS
- IE6+, FF, Safari, Opera: Almost Standards mode
XHTML 1.0 Frameset
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">