Coder Profile - Show off your skills, get a coder profile.
 
 
 
HTML vs XHTML
Web Development
I have noticed with a lot of new front end designers and developers, that their code is no where near XHTML compliant.

So here is a small article explaining how to better improve your code, and make it compatible for more users.

Lets go down to basics. What is the difference?

XHTML is a more "restricted" and "cleaner" version of HTML. It's restrictive in a good way. The idea of XHTML is to combine XML and HTML, to work on 99% of browsers, old browsers, mobile browsers. All of them.

So, what do I need to do?

Well first, XHTML requires the following tags.
Code Copy / Restore
  1. <!DOCTYPE the doctype>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.       <head>
  4.            <title>Title here</title>
  5.       </head>
  6.       <body>
  7.            Body stuff
  8.       </body>
  9. </html>
XHTML also requires all tags and attributes to be in lowercase.
Code Copy / Restore
  1. <A href="somelinkhere">Name</A>
  2.  
  3. <a HREF="somelinkhere">Name</a>
Both these examples are wrong. They should be:
Code Copy / Restore
  1. <a href="somelinkhere">Name</a>
All attributes must be quoted.
Code Copy / Restore
  1. <div width=50%>Stuff</div>
This is wrong, and should be:
Code Copy / Restore
  1. <div width="50%">Stuff</div>
ALL elements must be closed.
Code Copy / Restore
  1. <div>Stuff
  2. <br>Stuff
That may work fine in some browsers, but it is both unreadable by XML browsers, and not XHTML compliant.
Code Copy / Restore
  1. <div>Stuff
  2. <br />Stuff</div>
Notice the break has an extra " /" before the closing ">" this is to signify that it is an empty tag.

XHTML elements must be nested correctly.
Code Copy / Restore
  1. <strong><em>Hello, this is bold italics</strong></em>
This is not right, because the <em> tags should be nested within the <strong> tags. Like this:
Code Copy / Restore
  1. <strong><em>Hello, this is bold italics</em></strong>
Now all that is probably quite easy to follow, and should hopefully make sense. I agree with every point XHTML implies above. There is one small thing that I don't like about XHTML... Attribute Minimization.

This just means that when you have something like a drop down box, you can't use attributes like this:
Code Copy / Restore
  1. <option selected>Option</option>
You must have the FULL attribute, like this:
Code Copy / Restore
  1. <option selected="selected">Option</option>
Which to me makes little sense, but I figure it would be like setting the "selected" attribute to blank for certain browsers.

The last major thing about XHTML is that the "name" attribute is depreciated. You should use id instead, although for the most backward compatibility you should use both name and id with identical values.

That's about it, hope you understand a bit more about what XHTML is and why it is much, much better than HTML 4.01.


Posted By urbn
Please login to rate coding articles.

Click here to register a free account with us.
Comments
Please login to post comments.
 
Webcopper     Posted 76 Days Ago
 
 
Ummm personally I love HTML 4.01.. It's my specialty.. (x)HTML seems like.. a
whole lot extra with not a whole lot in return.. everyone I know at LEAST has IE 6 or
FF 2
 
JeffreySchultz     Posted 122 Days Ago
 
 
@mikeMarek,

The only difference between HTML and XHTML is it adheres to the XML syntax. In
laymen's terms, XHTML can be parsed by an ordinary XML parser without having to
know specific tags such as BR that are found in HTML. I had to write an HTML parser
for an HTML report document one time because it didn't follow XML syntax. The
most important reason to it's existence (the only argument that I would consider
valid); it's not just to make it look better.
 
mikeMarek     Posted 145 Days Ago
 
 
Thanks, that cleared up alot for me.... Little did I know I was already coding to
XHTML standards and all this time I was wondering wha the difference is.

Thanks!
-Mike
 
urbn     Posted 161 Days Ago
 
 
Of course it will be the same, you can't change what the XHTML rules are.

I posted this because I wanted to show that XHTML is the way forward, and is most
definitely what you need to be learning.

People may go to W3Schools, but often don't realise what "Learn
XHTML" means. I know that when I first started out, I didn't look at it.

Sorry if you think that I'm rehashing what is already available, but I
don't see enough new people doing the fundamentals of decent front end
development.
 
remy     Posted 161 Days Ago
 
 
would've been better if I wasn't able to read the same exact thing (and in
a more professional presentation) at w3schools.com
Page 1 of 1
More Articles By This Author
HTML vs XHTML
Recently Posted "Web Development" Articles
Speed Up Delivery of your JavaScript Libraries
A cool tool ^^
AJAX - When to use it?
Introduction To PHP
[PHP] XML
HTML vs XHTML
[PHP] XML: HTML DOM Basics
Embed flash into your website
When to use OOP in PHP
Module Development guide for Derangedminds
Recently Rated "Web Development" Articles
When to use OOP in PHP
Preventing raw PHP leaks on Apache
AJAX - When to use it?
Speed Up Delivery of your JavaScript Libraries
[PHP] XML
A cool tool ^^
HTML vs XHTML
Introduction To PHP
Embed flash into your website
[PHP] XML: HTML DOM Basics
source codes Categories articles
Browse All
Business & E-Commerce (1)
Databases (1)
Design & Creativity (1)
Internet & Web Sites (1)
Life In General (2)
Operating Systems (3)
Other (2)
Programming (48)
Security (10)
Software Development (4)
Web Development (12)
search Search Inside
Web Development
 
 
Part of the MyPingle Network
Development Blog :: Make A Donation :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved