XHTML Introduction

Jakob Jenkov
Last update: 2014-09-17

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:

<br>

In XHTML, however, the br element is an empty element, and must thus be written like this, to comply with XML rules:

<br/>

Notice the / 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:

attribute="value"

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.

Jakob Jenkov

Featured Videos

Java ConcurrentMap + ConcurrentHashMap

Java Generics

Java ForkJoinPool

P2P Networks Introduction

















Close TOC
All Tutorial Trails
All Trails
Table of contents (TOC) for this tutorial trail
Trail TOC
Table of contents (TOC) for this tutorial
Page TOC
Previous tutorial in this tutorial trail
Previous
Next tutorial in this tutorial trail
Next