BBC Home

Explore the BBC

h2g2
15th July 2009
Accessibility help
Text only

Guide ID: A1047845 (Edited)

Edited Guide Entry


SEARCH h2g2
Edited Entries only
Search h2g2Advanced Search


New visitors: Create your membership
Returning members: Sign in
BBC Homepage
The Guide to Life, The Universe and Everything.

3. Everything / Languages & Linguistics / Languages / Computer Languages
3. Everything / Maths, Science & Technology / Computers / Computer Languages and Programming

Created: 19th May 2003
The Differences between XHTML and HTML
Contact Us


Like this page?
Send it to a friend!

 

HTML stands for Hypertext Mark-up Language and XHTML stands for Extensible Hypertext Mark-up Language. Many people will be familiar with HTML, but they may not know about XHTML. They are both fairly similar; they both use tags and most, if not all, of the tags in HTML are available in XHTML. XHTML is based on XML1 and as such is much stricter with regards to coding.

The Differences

The main differences between HTML and XHTML are shown below.
While there are a few more differences than detailed below, the ones shown are the main ones that are likely to affect most people.
All the differences can be found in the W3C's XHTML specification in the Differences with HTML 4 section.

Closing and Nesting

All tags must be correctly nested - if a tag was started within another tag it must also be ended within that tag.

Correct:

<p>This text is <b>bold</b></p>

Incorrect:

<p>This text is <b>bold</p></b>

All tags must be closed. This includes tags that go around text2 and tags that define objects rather than format text - 'empty elements', such as <img> and <hr> which only have attributes and don't surround any text. Empty elements must be closed either with a closing tag or the start tag must end with /> rather than just >

Surrounding Tags:

Correct:

<p>This is some text</p>

Incorrect:

<p>This is some text

Empty Elements:

Correct:

<br></br> or <br/>

Incorrect:

<br>

So that XHTML documents are backwards compatible with HTML browsers, a space can be placed before the />, eg <br />.

Tags and Attributes

All tags and attribute names must be lower case. This is necessary for all HTML tags used in XHTML because XML is case sensitive - <b> and <B> are classed as different tags in XML.

Correct:

<a href="http://example.com"></a>

Incorrect:

<A HREF="http://example.com"></A>

All attribute values in tags must be quoted, even numbers

Correct:

<table border="200">

Incorrect

<table border=200>

Attribute minimization is not supported by XML. The attribute and value (ie attribute=value) must be written in full. So attribute names such as checked for form elements cannot occur on their own in tags.

Correct:

<input checked="checked">

Incorrect:

<input checked>3

In HTML, the name attribute was defined for certain tags4. The id attribute was also present. XML only uses the id attribute, therefore XHTML documents must use the id attribute to identify elements.
So that XHTML documents are backwards compatible with HTML browsers, both id and name attributes can be used.


1 Extensible Markup Language.
2 Such as <p>, <b>, and <a>.
3 It should be noted that the <input> tag requires more attributes than shown, but they are not relevant to the example.
4 <a>, <applet>, <form>, <frame>, <iframe>, <img>, and <map>.


Clip/Bookmark this page
This article has not been bookmarked.
ENTRY DATA
Written and Researched by:

R'win

Edited by:

The h2g2 Editors

Referenced Entries:

HTML Tags

Related BBC Pages:

BBC WebWise

Referenced Sites:

W3C
Differences with HTML 4
HTML Tidy

Please note that the BBC is not responsible for the content of any external sites listed.


CONVERSATION TOPICS FOR THIS ENTRY:

Start a new conversation

People have been talking about this Guide Entry. Here are the most recent Conversations:

TITLE
LATEST POST
Hey, uh, not wanting to be negative,May 20, 2003




Disclaimer

Most of the content on h2g2 is created by h2g2's Researchers, who are members of the public. The views expressed are theirs and unless specifically stated are not those of the BBC. The BBC is not responsible for the content of any external sites referenced. In the event that you consider anything on this page to be in breach of the site's House Rules, please click here. For any other comments, please start a Conversation above.




About the BBC | Help | Terms of Use | Privacy & Cookies Policy