BBC Home

Explore the BBC

Front Page

Life | The Universe | Everything | Advanced Search
 
Front PageReadTalkContributeHelp!FeedbackWho is Online
New visitors: Create your membership
Returning members: Sign in
 
3. Everything / Languages & Linguistics / Languages / Computer Languages
3. Everything / Maths, Science & Technology / Computers / Computer Languages and Programming

The Differences between XHTML and HTML

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>.

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

Hey, uh, not wanting to be negative,
(Last Posting: May 20, 2003)




Add your Opinion!

There are tens of thousands of h2g2 Guide Entries, written by our Researchers. If you want to be able to add your own opinions to the Guide, simply become a member as an h2g2 Researcher. Tell me More!

 
Entry Data
Entry ID: A1047845 (Edited)

Written and Researched by:
R'win

Edited by:
The h2g2 Editors


Date: 19   May   2003


Text only
Like this page?
Send it to a friend


Referenced Guide 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.

Most of the content on this site 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 to alert our Moderation Team. For any other comments, please start a Conversation below.
 


Front PageReadTalkContributeHelp!FeedbackWho is Online

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