Latest web development tutorials

XHTML Introduction

XHTML is an XML format written in HTML.


What is XHTML?

  • XHTML refers to the Extensible HTML
  • XHTML and HTML 4.01 are almost identical
  • XHTML is stricter and more pure HTML version
  • XHTML application by way of XML defined HTML
  • XHTML is the January 2001 W3C Recommendation published
  • XHTML by all major browsers support

Why use XHTML?

Internet page contains a lot of "bad" HTML.

If you look in a browser, the following HTML code to run very normal (even if it does not comply with HTML rules):

<Html> <Head> <Meta charset = "utf-8"> <Title> This is a non-standard HTML </ title> <Body> <H1> non-standard HTML <p> This is a paragraph </ body>

XML is a must properly marked and well-formed markup language.

If you want to learn XML, please read our XML Tutorial .

Today, the scientific community, there are some different browser technology. Some of which run on a computer, while others may run on mobile phones or other small devices. Small devices often lack explain "bad" markup language resources and capabilities.

So - by combining the strengths of HTML and XML, we developed XHTML. XHTML as XML redesigned HTML.


The most important difference compared with the HTML:

Document Structure

  • XHTML DOCTYPE is mandatory
  • <html> The XML namespace attribute is mandatory
  • <html>, <head>, <title> and <body> is mandatory

Element Syntax

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

Attribute syntax

  • XHTML attributes must be lowercase
  • XHTML attribute values must be surrounded by quotation marks
  • XHTML attribute minimization is forbidden

<! DOCTYPE ....> is mandatory

XHTML documents must be XHTML document type declaration (XHTML DOCTYPE declaration).

You can find the complete tutorial in this tag in the Reference Manual XHTML document type.

<Html>, <head>, <title>, and <body> element must exist, and must use <html> xmlns attribute in the document specified xml namespace.

The following example shows an XHTML document with a minimum of 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> <Meta charset = "utf-8"> <Title> Document Title </ title> </ Head> <Body> document content </ body> </ Html>


XHTML elements must be properly nested

In HTML, some elements can not be nested, like this:

<B> <i> italic and bold text </ b> </ i>

In XHTML, all elements must be nested with each other rational, like this:

<B> <i> bold and italic text </ i> </ b>


XHTML elements must have a closing tag

Examples of errors:

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

Right:

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


Empty elements must include a closing tag

Examples of errors:

Branches: <br> level: <hr> Photos: <img src = "happy.gif" alt = "Happy face">

Right:

Branches: <br /> Level: <hr /> Photo: <img src = "happy.gif" alt = "Happy face" />


XHTML elements must be in lowercase

Examples of errors:

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

Right:

<Body> <P> This is a paragraph </ p> </ Body>


Attribute names must be lowercase

Examples of errors:

<Table WIDTH = "100%">

Right:

<Table width = "100%">


Attribute values ​​must have quotes

Examples of errors:

<Table width = 100%>

Right:

<Table width = "100%">


Allowed shorthand property

Examples of errors:

<Input checked> <Input readonly> <Input disabled> <Option selected>

Right:

<Input checked = "checked"> <Input readonly = "readonly"> <Input disabled = "disabled"> <Option selected = "selected">


How to Convert HTML to XHTML

  1. Add a XHTML <! DOCTYPE> to your page
  2. Adding xmlns attribute to the html element of every page.
  3. Change all the elements to lowercase
  4. Close all empty elements
  5. Modify all attribute names to lowercase
  6. All attribute values ​​to add quotes

Using the W3C validator to test your XHTML

Please enter your URL in the box below: