loading comments

The structure of a XHTML document

Posted on: September 2, 2008 Categories: Tutorials
HTML

The structure of a XHTML document is slightly more different than a standard HTML. You will have certain parts in XHTML such as doctype’s and XML properties that HTML doesn’t have, there’s ultimately the same type of code language, but with changes, but it’s important to understand the basics of XHTML after all it’s the next generation of HTML so people should be in the know about it. In this tutorial you will learn about HTML, XHTML and there differences and the overall structure of both, and why it’s important to start using XHTML over HTML.

Whats’s the difference between XHTML and HTML?

HTML being the Standard Markup Language, being very flexible. XHTML is the “Next generation” of HTML, which was primarly placed in to allow XML and HTML to work better within a document. XHTML is more complex. A big change that XHTML brings is that your XHTML document must be well formed, or to others you may call it validation. XHTML must have no code errors to essentially be well formed and work correctly.

Why should you be using XHTML?

If your not already using XHTML then you really should be as XHTML as been implemented into newer versions of browsers and many pass the acid test so you should really transform your HTML into XHTML and seems XHTML is a advancement of HTML it isn’t hard to do.

You should also be using XHTML as it is now the standard that websites mark up should be coded in especially if you use XML.

Different versions of XHTML

XHTML has different versions, and they we’re all placed over-night. They were all released after one another months/years apart, new releases of XHTML were mainly created to fix certain attributes that needed to be agreed. Or implement new changes that a previous version of XHTML did have. There are also developments of new version of XHTML under way also has many browser foundations such as Mozilla and Opera have joined up with W3C to produce future XHTML versions.

Level of XHTML currenly range from XHTML 1.0 – XHTML 2.0 (With some versions in between)

What is DOCTYPE

Doc type is something that is not needed in HTML but is absolutely neccarsary for XHTML. A doctype is a small bit code which declares how the XHTML document will be produced and validate. A typical doctype can be found here:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

This bit of code would go on line 1 of any XHTML document and tell a XHTML parser how to declare it. Doc type also relates to the versions of XHTML, your version of XHTML and Doc type must be correct to validate correctly there more doc type’s depending on your website.

The structure of HTML & XHTML:

Now that we’ve got the theory part out of the way it’s time to see some code in action. Before we look at XHTML here is your everyday HTML document:

<html>
<head>
<title>HTML Document</title>
</head>

<body>
</body>
</html>

The very basic HTML structure, notice how it only uses attributes and nothing else.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Notice when I was talking about the doc type and where it goes within a XHTML document, you will also notice the XML properties within a XHTML document and the XHTML document uses other non HTML attributes.

Let’s compare HTML and XHTML in it’s structure:

  • Doc type is present in XHTML but not HTML
  • HTML/XHTML tags are both present in XHTML but not HTML
  • XML can be specified within the XHTML document but not in a HTML document
  • Both follow the standard HTML structure, but XHTML has it’s own structure additions as well

So we can determine from this that HTML and XHTML are simular, but HTML can’t use XHTML code if it’s not set as XHTML document, but XHTML can use HTML code even if it’s set a XHTML document.

Page extensions that HTML/XHTML can be saved in:

There are essentially two page extensions that XHTML/HTML can be saved in to become a HTML webpage, .htm and .html, however XHTML/HTML can be placed in other page extensions such as PHP or ASP. The problem is with the two HTML webpage extension is that one of them should not be used in webpage’s today. I’ll explain.

The .htm extension has become more of a bad habit than anything as it basically existed when programs like text editors would only except 3 character file extensions (.doc .txt etc) but since this 3 character restriction was lifted the extension .html now existed and the .html is actually the correct extension to use.

.htm is more of the short version and isn’t actually correct, however they both do the same job and if you were to use .htm it’s not the end of the world.

Well thats my tutorial on XHTML and HTML I hope you learnt some useful info from it!

I'm James, I'm 18 years old and I'm a freelance website developer from Nottingham, England. I have a passion for website development and have designed websites for a range of clients in my freelance years. James' Blog is my personal blog where I post articles and general posts whenever I can. I typically like talking website development, but you'll find a range of posts and articles here on my blog.

  • http://www.mynetfaves.com/tags/xhtml Recent Faves Tagged With “xhtml” : MyNetFaves

    [...] public links >> xhtml The structure of a XHTML document First saved by LisaNova | 0 days [...]

  • Joseph

    Thanks man. Great resource for a total newbie.

  • http://www.james-blogs.com James

    No problem Joseph!

  • http://infoeduindia.com/2009/06/04/the-structure-of-a-xhtml-document/ The structure of a XHTML document – Tutorial Collection

    [...] View Tutorial No Comment var addthis_pub=”izwan00″; BOOKMARK This entry was posted on Thursday, June 4th, 2009 at 1:31 am and is filed under Html Tutorials. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site. [...]

  • http://eudesign.lt Anthix

    Hmm. for me tahts was good article to remeber. :) becous 5 yers ago i was typing web pages bus i had a new job and was forgot all :)

  • poop

    its learned, not learnt.

blog comments powered by Disqus