XHTML Introduction

XHTML 是以 XML 格式编写的 HTML。

XHTML is HTML written in XML format.

  • What is XHTML?
  • XHTML refers to Extensible Hypertext Markup Language
  • XHTML is almost the same as HTML 4.01
  • XHTML is a stricter and purer version of HTML
  • XHTML is defined as HTML applied in the way of XML XHTML isJanuary 2001
  • The published W3C recommended standard

XHTML is supported by all mainstream browsers

Why use XHTML?

Many web pages on the Internet contain 'bad' HTML.

If viewed in a browser, the following HTML code runs very normally (even though it does not comply with HTML rules):
<head>
<html>
<body>
<title>This is bad HTML</title>
<h1>Bad HTML
</body>

<p>This is a paragraph

XML is a markup language that must be properly marked and well-formed. If you want to learn XML, please read our.

XML Tutorial

Today's technology industry exists some different browser technologies. Some run on computers, while others may run on mobile phones or other small devices. Small devices often lack the resources and capabilities to interpret 'bad' markup languages.

So - by combining the strengths of XML and HTML, XHTML was developed. XHTML is a re-designed HTML as XML.

The most important difference compared to HTML:

  • document structuremandatory
  • The XHTML DOCTYPE ismandatory
  • The XML namespace attribute in <html> is alsomandatory

element syntax

  • XHTML elements mustbe correctly nested
  • XHTML elements must alwaysbe closed
  • XHTML elements mustin lowercase
  • An XHTML document must havea root element

attribute syntax

  • XHTML attributes must usein lowercase
  • XHTML attribute values must be usedEnclosed in quotes
  • The minimization of XHTML attributes is alsoProhibited

The <!DOCTYPE ....> is mandatory

An XHTML document must declare the XHTML document type (XHTML DOCTYPE declaration).

You can find the complete reference manual for tags on CodeW3C.com. XHTML Document Type.

The <html>, <head>, <title>, and <body> elements must also be present, and the xmlns attribute in the <html> must be used to define the XML namespace for the document.

The following example shows an XHTML document with the minimum required tags:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title of document</title>
</head>
<body>
......
</body>
</html>

How to Convert from HTML to XHTML

  1. Add the XHTML <!DOCTYPE> to the first line of each page
  2. Add the xmlns attribute to the html element of each page
  3. Change all element names to lowercase
  4. Close all empty elements
  5. Change all attribute names to lowercase
  6. Quote all attribute values

Validate your XHTML with the W3C Validator

Enter your website URL in the text box below:

XHTML Quiz

The quiz contains 20 questions and there is no time limit.

This quiz is informal and is just a good way to get an idea of your level of knowledge of XHTML.

Each correct answer is worth 1 point. After the test is over, your total score will be displayed. The highest score is 20 points.

Start the XHTML Quiz