The whole world knows that the whole world presents web content using HTML (HyperText Markup Language). These HTML pages are written by programmers (and if generated by designers, then are at least optimized by programmers), and many programmers are, unfortunately, unprofessional in their approach!
Why is HTML bad?
HTML is notoriously well-known for being very loose and extremely tolerant, and never produces a syntax error. If there is something it can’t understand, it will at most ignore it or try to render it using whatever default rule that is in effect at the time of understanding the content. A professional never relies on the assumptions that web browsers (whose job is to understand and render HTML content) make, and writes code that has a consistent appearance across users and browsers.
How to be professional?
The most important fundamental step in this regard is to switch to XHTML instead of using just plain HTML. XHTML stands for eXtensible HTML, a name that is derived from the fact that XHTML follows XML (eXtensible Markup Language) rules. XHTML, like XML, is very strict and particular about how markups (also called tags or elements) are used within the document, unlike HTML.
The fundamental difference between HTML & XHTML
The main difference between HTML and XHTML, semantically, is that XHTML is supposed to be an “error-free” document, based on XML rules, whereas an HTML document could well be ill-formed. The only difference between HTML and XHTML from this perspective is that an XHTML document with errors is simply not a valid XHTML document at all!
XHTML Validation
Validators exist that can verify whether a given document is valid XHTML or not. In fact, any XML validator can validate an XHTML file! Online XHTML validators exist that can validate XHTML input that is either typed, or uploaded, or can validate online pages whose link is submitted. Some of these online validators are:
- The W3C Offical Markup Validation Service (http://validator.w3.org/)
- A general validator service or HTML, XHTML, WML and XML: http://www.validome.org/
- A tutorial site that has validator service as an extension of the tutorial: http://www.w3schools.com/website/web_validate.asp
- Web design group’s HTML validator (http://www.htmlhelp.com/tools/validator/). They also have an offline validator that can be downloaded and run on your system.
- A commercial validator (https://www.htmlvalidator.com/)
A webpage that uses valid XHTML can proudly announce the same to visitors using standard badges created by the W3C:
Image link: http://www.w3.org/Icons/valid-xhtml11.png
Image link: http://www.w3.org/Icons/valid-xhtml11-blue.png
Steps to convert HTML to XHTML
Now that you’ve decided to be professional and convert your HTML documents into XHTML, the question is what changes are to be made? To generalise, the question would be: what are the differences between HTML and XHTML? The differences are covered below, one by one:
1. XHTML element (tag) names are case-sensitive, and in lowercase.
HTML | XHTML |
---|---|
<BODY> | <body> |
<Body> | <body> |
2. XHTML tags need to be properly paired and nested.
HTML | XHTML |
---|---|
<p>This is a <b>Demo</p> | <p>This is a <b>Demo</b></p> |
<p>First para <p>Second para <p>Third para | <p>First para</p> <p>Second para</p> <p>Third para</p> |
3. Unpaired tags (empty elements) need to have a trailing slash.
HTML | XHTML |
---|---|
<br> | <br/> |
4. XHTML attributes are always quoted.
HTML | XHTML |
---|---|
<table border=1> | <table border=”1”> |
<table border=1> | <table border='1'> |
5. XHTML attributes need to compulsorily have quotes even when the value is empty.
HTML | XHTML |
---|---|
<img src=1.gif alt /> | <img src=”1.gif” alt=”” /> |
6. XHTML documents need to have only one root element: html.
HTML | XHTML |
---|---|
<head><title></title></head> <body></body> | <html> <head><title></title></head> <body></body> </html> |
7. XHTML documents need to compulsorily have <html>, <head>, <title> and <body> tags.
HTML | XHTML |
---|---|
<html> <body></body> </html> | <html> <head><title></title></head> <body></body> </html> |
8. XHTML documents compulsorily need to have a document type declaration (DOCTYPE) and the xmlns attribute of <html> must specify the xml namespace for the document.
HTML | XHTML |
---|---|
<html> <body></body> </html> | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title></title></head> <body></body> </html> |
Resources
The W3C Quality Assurance Tools can help you further in developing professional code and web sites.
Related Articles
No user responded in this post