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.
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 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:
We quote the value like done below:
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:
These elements would need to be closed with a slash at the end, like in the below example:
The DTDs of XHTML are as follows.The Strict Doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
The Transitional Doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The Frameset Doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
We should also qualify the elements and attributes through the xmlns attribute on the root element, this is done like below:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
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
Example of an Valid XHTML Page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Valid XHTML Page</title> <meta name="description" content="Tutorials and References." /> <meta name="robots" content="index,follow" /> </head> <body> <p>This is likely to be<br /> your first valid XHTML page</p> </body> </html>
You should also read the Article: XHTML vs HTML