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  ::  Remove Scroll Bars
  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  ::  Remove Scroll Bars
  1. <A href="somelinkhere">Name</A>
  2.  
  3. <a HREF="somelinkhere">Name</a>
Both these examples are wrong. They should be:
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. <a href="somelinkhere">Name</a>
All attributes must be quoted.
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. <div width=50%>Stuff</div>
This is wrong, and should be:
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. <div width="50%">Stuff</div>
ALL elements must be closed.
CODE: Copy / Restore  ::  Remove Scroll Bars
  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  ::  Remove Scroll Bars
  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  ::  Remove Scroll Bars
  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  ::  Remove Scroll Bars
  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  ::  Remove Scroll Bars
  1. <option selected>Option</option>
You must have the FULL attribute, like this:
CODE: Copy / Restore  ::  Remove Scroll Bars
  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 3.65 Years 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 3.78 Years 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 3.84 Years 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 3.89 Years 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 3.89 Years 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
Website Optimization
How to use Memcache on Windows
PHP Sessions = Member Database Cache
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
Recently Rated "Web Development" Articles
Embed flash into your website
PHP Sessions = Member Database Cache
What makes a good PHP programmer?
Website Optimization
Preventing raw PHP leaks on Apache
How to use Memcache on Windows
AJAX - When to use it?
Speed Up Delivery of your JavaScript Libraries
[PHP] XML
A cool tool ^^
source codes Categories articles
Browse All
Business & E-Commerce (1)
Databases (1)
Design & Creativity (1)
Hardware (1)
Internet & Web Sites (3)
Life In General (2)
Networking (1)
Operating Systems (4)
Other (2)
Programming (46)
Security (8)
Software Development (5)
Web Development (14)
search Search Inside
Web Development
 
 
Latest News About Coder Profile
Coder Profile Poll
Which sounds better on your coder profiles, and makes more sense to you (think twitter, facebook, etc)?

Followers / Following
Fans / Following
Fans / Fan Of


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
3.20 Years Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2012, Scott Thompson, All Rights Reserved