Introduction to XHTML

Introduction

Although plain HTML has come a long way, XHTML represents the future of HTML. XHTML better structures HTML to take advantage of many of the features of XML. And best of all, XHTML is compatible with today's newest browsers.

What is XHTML?

XHTML is HTML markup that follows a more rigorous XML-style formatting and is the standard for HTML development going forward.

Today, most browsers still display old or poorly applied HTML. Because it has stricter rules for applying markup, XHTML will, in the long run, provide better performance than HTML, especially for a wider variety of Web-connected devices, including cell phones and handheld devices.

Although browser support for HTML will probably not disappear overnight, with a few modifications, you can start applying the XHTML standards in your Web pages right away.

Well-formed XHTML code

All XHTML Web pages must be well-formed. This means that:

 Tags and attributes must be lowercase.  Unlike HTML, XHTML is case-sensitive. HTML has never been case-sensitive (for instance, the tag
is treated the same as the tag
), but HTML 4.0 recommends that HTML elements and attributes be lowercase, and XHTML 1.0 requires lowercase tags.

 Elements that encapsulate data have beginning and ending tags.  Empty elements (meaning tags that don't have ending tags, such as and
) use the forward slash at the end of the tag (for example, or
).

 Tags must be properly nested, as in the following example:

Some information.

Notice that the and tags are enclosed within and tags, which are contained within the

and

tags. Also notice that the
tag includes the trailing forward slash (the end tag) within it.  Deprecated HTML presentation tags such as must be replaced by CSS  All script and style tags should have a type attribute  Attribute values must be lower case  Attribute values must be surrounded by quotation marks.  The alt attribute is required for all images, even if the value is empty (for example, alt="").  Attributes cannot be minimized  An example of a minimized attribute is the following:

The same attribute as well-formed XHTML looks like this:

 Finally, one of the following DOCTYPE declarations (DTD) must appear at the top of the page:  Strict:

 Transitional:

 Frameset:

Valid XHTML code

All XHTML Web pages must be valid. This means that the code has been checked against a formal standard (called a schema) and has met all the requirements of that standard. The standard is defined by the inclusion of a document type declaration (DTD) at the top of the code page before the tag. Although an explicit document type definition declaration is optional in HTML, in XHTML it is required.

The XHTML DOCTYPE declaration tells a Web browser what kind of structure (elements and attributes) to expect to find in the page. The following is an example of a DOCTYPE declaration in XHTML 1.0:

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

XHTML 1.0 defines the following three DTDs, which are similar to those in HTML 4.01 and are designed to help migrate existing HTML Web pages to XHTML:

 Strict: Used for a Web page that uses cascading style sheets (CSS). Most HTML formatting-related attributes (such as align) are not supported in favor of the id, class, and style attributes used with CSS.

 Transitional: Used for a page that needs to continue to use HTML formatting-related attributes for older browsers that do not support CSS.  Frameset: Used for a page that supports frames.

For more information on DOCTYPE declarations, see Working with HTML DOCTYPE Declarations.

XHTML Web pages require more than a DTD declaration to be valid. You also need to test the validity of your page and fix any coding errors that appear. Luckily, there are online tools available to help you test the validity of your page. After your Web page is ready in XHTML, you can use the W3C Markup Validation Service to identify and resolve and coding errors you might have, or to verify that the XHTML you wrote is indeed valid code.

Conclusion

XHTML not only combines the best of XML and HTML 4.01, it is the future standard for Web programming. Best of all, because XHTML is still HTML, it is as compatible with older browsers as HTML 4.01.

About the author:

Jeannine Gailey is owner of Webbish6, author, and Web consultant.