WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

HTML and XHTML


XHTML is HTML 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 HTML defined as an XML application
  • XHTML is a January 2001 W3C Recommendations
  • XHTML is supported by all major browsers

Why use XHTML?

Many pages on the Internet contain "bad" HTML.

The following HTML code works perfectly if viewed in a browser (even if it doesn't follow HTML rules):

<html>
<head>
  <title>This isn't finished HTML</title>

<body>
  <h1>not complete tag HTML
  <p>This is a paragraph
</body>

XML is a well-formed markup language that must be properly tagged.

Some different browser technologies exist in the tech world today. Some of them 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-XHTML was developed by combining the strengths of XML and HTML. XHTML is HTML redesigned as XML.



The Most Important Differences from HTML:

Document Structure

  • XHTML DOCTYPE Is mandatory
  • <html> XML namespace in Attribute is mandatory
  • <html>、<head>、<title> 以及 <body> Also mandatory

Element syntax

  • XHTML elements must be properly nested
  • XHTML elements must always be closed
  • XHTML elements must be lowercase
  • XHTML documents must have a root element

Attribute syntax

  • XHTML attributes must use lowercase
  • XHTML attribute values must be enclosed in quotes
  • XHTML attribute minimization is also forbidden


<!DOCTYPE ....> Is Mandatory

XHTML documents must make XHTML DOCTYPE declarations.

You can find the complete XHTML Doctypes is found in our HTML Tags Reference.

The <html>, <head>, <title>, and <body> components should likewise be available, and the xmlns characteristic in <html> must determine the xml namespace for the document.

The following example shows an XHTML document with minimal required tags:

<!DOCTYPE html Open "-/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>
  some content
</body>

</html>

XHTML Elements Must Be Properly Nested

In HTML, some elements may not be nested inside each other, like this:

<b><i>This content is strong and italic</b></i>

In XHTML, all elements must be properly nested within each other, like this:

<b><i>This content is intense and italic</i></b>

XHTML Elements Must Always Be Closed

This is wrong:

<p>This is a paragraph
<p>This is another paragraph

This is correct:

<p>This is a paragraph</p>
<p>This is another paragraph</p>

Empty Elements Must Also Be Closed

This is wrong:

A break: <br>
An even guideline: <hr>
A picture: <img src="happy.gif" alt="Happy face">

This is correct:

A break: <br/>
A level principle: <hr/>
A picture: <img src="happy.gif" alt="Happy face"/>

XHTML Elements Must Be In Lower Case

This is wrong:

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

This is correct:

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

XHTML Attribute Names Must Be In Lower Case

This is wrong:

<table WIDTH="100%">

This is correct:

<table width="100%">

Attribute Values Must Be Quoted

This is wrong:

<table width=100%>

This is correct:

<table width="100%">

Attribute Minimization Is Forbidden

Wrong:

<input type="checkbox" name="vehicle" value="car" checked/>

Correct:

<input type="checkbox" name="vehicle" value="car" checked="checked"/>

Wrong:

<input type="text" name="lastname" incapacitated/>

Correct:

<input type="text" name="lastname" disabled="disabled"/>

How to Convert from HTML to XHTML

  1. Add a XHTML <!DOCTYPE> To your web page
  2. Add the xmlns attribute to the html element of each page.
  3. Change all elements to lowercase
  4. Close all empty elements
  5. Change all attribute names to lowercase
  6. Quotation marks for all attribute values


Validate XHTML With The W3C Validator

Put your web address in the case below: