XHTML is a version of HTML which is based on XML. There are a few differences between XHTML and HTML. These differences are:
- All XHTML elements must either have an end-tag, or be marked as empty elements using a special syntax.
- All attributes must be enclosed in double quotes ("), and they must have a value.
XML Syntax for HTML Elements
In HTML the
br element can be written like this:
In XHTML, however, the
br element is an empty element, and must thus be written
like this, to comply with XML rules:
/ after the element name, marking this element as an empty element.
XML Syntax for Attributes
XHTML documents must follow the XML syntax, and that means that all element attributes must be written like this:
You cannot use single quotes around the attribute value, and you cannot omit the quotes either.
XHTML and HTML5
XHTML was originally planned to replace HTML, but with HTML5 the opposite is actually happening. HTML5 makes XHTML obsolete. Therefore XHTML is not that interesting to study, except for use in EPUB books.
XHTML and EPUB
The HTML files used in EPUB e-books must be in XHTML syntax, even if the files are using HTML5 elements. That means that the documents must conform to the two rules listed earlier - meaning no opening tags without closing tags too, and attributes must be enclosed in double quotes.