Saturday, February 18, 2006

Making the Switch to XHTML from HTML 4

Although XHTML has been around for a long while, many websites have not been made to be XHTML compliant and as a matter of fact, not 508 compliant... This poses issues as the major search engines like Google, Yahoo!, MSN and ASK are starting to or will be adhering tightly to standard coding which has been brought up to speed with usability, accessibility and "clean code", and at this time of writing the standard is XHTML.

While I will admit in many ways it is easy as web coding professionals with many years of experience to continue coding HTML 4, as it is easier, but there are many reasons why we should not. First, HTML is clunky and quite honestly, poorly coded and heavy. Second, if you are serious about promoting your website, services or products, then you must keep up with search engine trends and Internet standards with regard to demand.

What is XHTML?


XHTML is an acronym for Extensible Hypertext Markup language and is comprised of a mix of the best elements from HTML and XML, indeed a hybrid. XHTML was developed to create a stricter standard for web pages, to reduce incompatibilities between browsers, and to create a universal standard for document format which could be used on different platforms, devices, etc.

XHTML is Prime


The best thing about XHTML is that it is almost the same as HTML. While you cannot get away with lazy coding practices, it may actually be better for coders since the page coding is kept to a minimum and layouts are cleaner.

Changes in XHTML Vs. HTML


There are several main changes to the way an XHTML page is formed that HTML has never conformed to:

  • All tags must be lowercase

  • Example: <font> NOT <Font> OR <FONT>
  • Each page must have a defined DOCTYPE declaration

  • Documents must be properly formed

  • All tags must be well formed

  • Example: <br> must now be <br> AND <img alt="" src="a.gif" /> is now <img alt="" src="a.gif" /gt;
  • Certain attibutes have been made obsolete

  • The name attibute is different now

  • Example: <img src="a.gif" name="name" /> MUST NOW BE <img id="name" src="a.gif" />
  • Attributes cannot be shortened

  • All tags must be properly nested


About DocType


There are three types for XHTML: Strict, Transitional and Frameset.
Here are examples of those DOCTYPE declarations -

Strict


Strict is to be used if the page markup is very clean and is much more difficult to adhere to.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/XHTML1/DTD/xhtml1-strict.dtd">

Transitional


This is to be used if you still require certain use of HTML or if you prefer your code to be somewhat loose (while adhereing to XHTML standards of course).


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

Frameset


If you use frames, this is the declaration for you.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3c.org/TR/XHTML1/DTD/xhtml1-frameset.dtd">

Note: The declaration should be used in the very first line of your XHTML page. Since the DOCTYPE declaration is a comment tag in essence to older browsers, you do not have to worry about any such related issues.

In addition to making tags lowercase, adding alt attributes to every image (they can be empty) and not shortening attributes (ie: <input type="checkbox" name="true"> NOW IS <input type="checkbox" href="http://www.website.com" named="true">, but now it must be formed like: <a href="http://www.website.com">.

There are other things to take not of when it comes to validating for XHTML, but these elements are some of the biggest and most common to adapt. Changing these to be XHTML compliant will certainly make the process easier and swifter. Good luck and Good Coding!

No comments: