HTML - XHTML


XHTML is written in XML format.


What is XHTML?

  • XHTML stands for Extensible HyperText Markup Language.
  • XHTML is almost the same as HTML 4.01.
  • XHTML is a stricter and cleaner version of HTML.
  • XHTML is defined in the way of XML applications.
  • XHTML isJanuary 2001W3C Recommendation Standard published in January 2001
  • XHTML is supported by all major browsers.

Why use XHTML?

Many pages on the Internet contain "poor" HTML.

If you view this HTML code in a browser, it runs normally (even though it doesn't follow HTML rules):

<html> <head> <meta charset="utf-8"> <title>This is an irregular HTML</title> <body> <h1>Irregular HTML<p>This is a paragraph</body>

XML is a markup language that must be correctly marked and formatted.

If you want to learn XML, please read ourXML Tutorial。

Today's technology industry exists with 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 "poor" markup languages.

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


The most important difference from HTML:

Document Structure

  • The XHTML DOCTYPE isMandatory
  • The XML namespace attribute in <html> isMandatory
  • <html>, <head>, <title>, and <body> areMandatory

Element Syntax

  • XHTML elements mustbe properly nested
  • XHTML elements must alwaysbe closed
  • XHTML elements mustbe lowercase
  • XHTML documents must havea root element

Attribute Syntax

  • XHTML attributes must uselowercase
  • XHTML attribute values must be enclosed in quotesXHTML attribute minimization is
  • prohibited<!DOCTYPE ....> is mandatory

<!DOCTYPE ....> is mandatory

You can find the complete XHTML document type in the tag reference manual of Tutorial.

Add an XHTML <!DOCTYPE> to your webpage.Add the xmlns attribute to each <html> element.

Change all elements to lowercase.

Close all empty elements.

<!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> <meta charset="utf-8"> <title>Modify all attribute names to lowercase.</title> </head> <body>Add quotes to all attribute values.</body> </html>


XHTML elements must be properly nested

Enter your URL in the following input box:

<b><i>Other Extensions</b></i>

AI Thinking...

<b><i>HTML Summary</i></b>


XHTML elements must have closing tags

Note List

<p>Click here to share notes<p><p style="font-size:14px;">Notes need to be an expansion of the content of this article!</p><br> <p style="font-size:12px;"><a href="../tougao.html" target="_blank">Submit article, click here</a></p> <p style="font-size:14px;"><a href="../w3cnote/example-user-test-intro.html" target="_blank">Get the registration invitation code</a></p> <h3 class="text-muted"><i class="fa fa-info-circle" aria-hidden="true"></i> Before sharing notes, you must <a href=";.html" class="example-pop">log in</a>!</h3> <p><a href="../w3cnote/example-user-test-intro.html" target="_blank">Get the registration invitation code</a></p>

Cancel

<p>Share Note</p> <p>Nickname</p>


Empty elements must have closing tags

Email

Email (required)<br>Reference Address<hr>Reference Address<img src="happy.gif" alt="Happy face">

correct example:

Branch:<br />horizontal line:<hr />image:<img src="happy.gif" alt="Happy face" />


XHTML elements must be lowercase

incorrect example:

<BODY> <P>This is a paragraph:</P> </BODY>

correct example:

<body> <p>This is a paragraph:</p> </body>


Attribute names must be lowercase

incorrect example:

<table WIDTH="100%">

correct example:

<table width="100%">


Attribute values must be enclosed in quotes

incorrect example:

<table width=100%>

correct example:

<table width="100%">


Attribute shorthand is not allowed

incorrect example:

<input checked> <input readonly> <input disabled> <option selected>

correct example:

<input checked="checked"> <input readonly="readonly"> <input disabled="disabled"> <option selected="selected">


How to convert HTML to XHTML

  1. Add an XHTML <!DOCTYPE> to your webpage:
  2. Add an xmlns attribute to each html element in your page.
  3. Change all elements to lowercase.
  4. Close all empty elements.
  5. Change all attribute names to lowercase.
  6. Add quotes to all attribute values.

Use the W3C validator to test your XHTML

Please enter your URL in the following input box:

Other extensions: