Posted by: prajapatinilesh | November 22, 2007

why is XHTML better than HTML 4.0?

I am sure, you all know about XHTML – The Extensible HyperText Markup Language. Then why I am writing about XHTML now? hm… good question!

I want to know, why XHTML is better than HTML 4.0? What is in XHTML that helps us going forward? How to convert HTML 4 documents to XHTML documents?

XHTML is an extention of HTML 4.01 and is XML based, well formed, and designed to work with XML-based user agents (like browsers).

If you have been coding in HTML 4.01 standards, you can eazily follow XHTML too.
I am just listing down the points I have noted down to write an XHTML document.

  1. XHTML (for that matter HTML 4.01 too), requires that you separate out presentation from content. You need to avoid using font, color and alignment tags in HTML. Instead, style sheets are preferred.
  2. Use title attribute everywhere. Add title attribute to <a> tags, abbreviations, and anywhere explanation helps.
  3. Use alt, accesskey, lang and label attributes everywhere.
  4. Start using id instead of name attribute. Id will help you identify the element in DOM. This is important for using style sheets too.
  5. Add summary tag to your table. Again, this will improve accessibility.
  6. Keep all the tags in lowercare
  7. Close and correctly nest all tags
  8. Close empty tags using space /> like <br />
  9. XML does not support attribute minimization. Attribute-value pairs must be written in full. For example, wrap=”wrap” is required to specify word wrap.
  10. Use double quotes to specifiy values to attributes, like border=”1″
  11. Embed style sheets and scripts in CDATA section.
  12. Avoid line breaks and multiple white space characters within attribute values.
  13. Use both the lang and xml:lang attributes when specifying the language of an element. The value of the xml:lang attribute takes precedence.
  14. make sure that, XML namespace and DOCTYPE lines at the beginning of the page

It is important to use CSS in conjunction with XHTML to produce consistant web pages.

I would recommend using Html Validator Extension for Firefox and Mozilla or HTML Tidy to help you validate the XHTML. The warnings and error messages will guide you to learn more about XHTML.

Reference

  1. XHTML 1.0 Specifications at W3C
  2. NYPL Style Guide
  3. XHTML 1.0 Reference
  4. XHTML Quiz
  5. XHTML Article at WikiPedia
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: