By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

An Introduction to XHTML

This Introduction show beginners how to work with XHTML.

Edited: 2012-10-23 21:05

XHTML is a reformation of HTML in XML, you will find that coding valid XHTML is as easy as coding HTML. Most of the elements and attributes are the same, and as such its easy to learn XHTML.

Coding XHTML

There are some coding related changes you must make before your code will be valid. Rather then repeating everything in the HTML Tutorial, I'll simply explain about these changes.

Attribute Values

Attribute values must be quoted, while this isn't a requirement in HTML, even in HTML leaving attribute values as unquoted is generally considered a bad practice. So instead of:

<element attribute=value>

We quote the value like done below:

<element attribute="value">

Its also recommended to quote attribute values in HTML.

Lowercase Elements and Attributes

In XHTML all elements must be lowercase, as with attributes. It is also recommended to use lowercase for attributes and elements in HTML, not doing so is generally considered a bad practice.

Empty elements must be Closed

Empty elements are elements which normally wouldn't have a closing tag, the paragraph element used to belong in this group, since its closing tag was optional. The closing tag of the Paragraph is however required in later versions of HTML. Examples of elements that this would effect are:

br, hr, meta, img, link, base, col, area, input, frame, param

These elements would need to be closed with a slash at the end, like in the below example:

<element />


The DTDs of XHTML are as follows.

The Strict Doctype:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

The Transitional Doctype:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

The Frameset Doctype:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"

We should also qualify the elements and attributes through the xmlns attribute on the root element, this is done like below:

<html xmlns="" xml:lang="en" lang="en">

Mime Types

It is also recommended to serve XHTML pages with the correct mime type, and then advise your users to upgrade if their user agent doesn't support XHTML. More about this in the Article: XHTML and Mime Types

An Example

Example of an Valid XHTML Page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="" xml:lang="en" lang="en">

    <title>Valid XHTML Page</title>
    <meta name="description" content="Tutorials and References." />
    <meta name="robots" content="index,follow" />

    <p>This is likely to be<br /> your first valid XHTML page</p>


You should also read the Article: XHTML vs HTML