Skip to main content

XHTML Tips And Tricks

A few tips that can help you create correct and effective XHTML documents.

Tips for Designing XHTML Document

Some basic guidelines for designing XHTML documents:

Design for Serving and Engaging Your Audience

The document must be effective so that it is easy to find the information you need within the document.

Reuse Your Document

Reusing previously created documents as the basis for new documents.

Inside the XHTML Document

Some suggestions concerning the elements within the XHTML document

The XML Declaration

An XML declaration is not required in all XHTML documents, but authors of XHTML documents are strongly encouraged to use XML declarations in all their documents. Such a declaration is required when the document's character encoding is different from the default UTF-8 or UTF-16.

Empty Elements

They include a space before the trailing / and > of empty elements. For example, <br />, <hr />, and <img src="/html/xhtml.gif" alt="xhtml" />.

Embedded Style Sheets and Scripts

Use external style sheets if your style sheet uses <, &, ]]>, or -.

Use external scripts if your script uses <, &, or ]]>, or -.

Line Breaks within Attribute Values

Avoid line breaks and multiple whitespace characters within attribute values. These are handled inconsistently by different browsers.

isindex Element

Do not include more than one isindex element in the document header. The isindex element is deprecated in favor of the input element.

The lang and xml:lang Attributes

Use both the lang and xml:lang attributes while specifying the language of an element. The value of the xml:lang attribute takes precedence.

Element Identifiers

XHTML 1.0 has deprecated the name attributes of the a, applet, form, frame, iframe, img, and map elements. They will be removed from XHTML in later versions. Therefore, start using the id element for element identification.

Using Ampersands in Attribute Values

The ampersand character (&) should be presented as an entity reference &.

Whitespace Characters in HTML and XML

Some characters that are legal in HTML documents are illegal in the XML document. For example, in HTML, the form-feed character (U+000C) is treated as white space; in XHTML, because of XML's character definition, it is illegal.

Named Character Reference &Apos;

The reference to the name character ' (the apostrophe, U+0027) was introduced in XML 1.0 but does not appear in HTML. Web developers should therefore use &#39; instead of ' to function as intended in HTML 4 web browsers.