XHTML is an enhanced strict version of HTML for web browsers. However both languages used for web development but different from each other in many ways. Many loose rules followed by traditional HTML makes a way for XHTML to comply with web standards in a strict manner. World Wide Web Consortium(W3C) also encourages new web technologies like HTML5 and XHTML to meet new web standards. It design and validate the architecture of the web browsers to render any web page over the web according to the latest web technologies.
In this article i have mentioned about the required rules for XHTML, which is a core of XHTML and meet W3C standards. So let’s understand below mentioned rules for XHTML one by one for developing rich web applications for browsers.
a) Values for attributes may be Case Sensitive in XHTML
Elements and attributes syntax in traditional HTML is Case Insensitive which means if we write below code as:
<a HREF="captain.png">Click Here</a> OR <a href="captain.png">Click Here</a>
This would perfectly rendered by web browsers. But In the case of XHTML this is not true in few cases. For example: If we write the same code for UNIX based web server’s then attribute value might not match the exact file.
Original file: captain.png
<a href="captain.png">Click Here</a> OR <a href = "CAPTAIN.png">Click Here</a>
Note: On UNIX based web server file names are case sensitive.
While on the other side on windows web server, where file names are not case sensitive so above code will run smoothly.
b) XHTML follows Valid element structure
As we compare XHTML to HTML, XHTML follows valid element structure than HTML. With its proper and valid nesting of elements into other elements enhance the usability of web applications. For example: if we write below mentioned code then it would run but do not comply with XHTML guidelines.
<h2>Examples copyright to 87android</h2>
Above mentioned code should contain valid elements related to “<table>” such as “<tr>” and “<td>”, instead of “<h2>” element. However, this will run properly in browsers, but it lacks valid code structure.
c) Elements should have closing tags(< / >)
While writing code in HTML we sometimes forget or do not close elements, but in XHTML we need to close all tags. For example if we write:
<strong>Welcome to the World <!-- Incomplete code -->
<strong>Welcome to the World</strong> <!-- Complete code -->
Empty elements like “<hr>” and “<br>” also do not have closing tags because both elements do not enclose any content. But in XHTML we need to close every elements via self closing format (<br/>).
d) Proper nesting of elements compulsory in XHTML
In HTML we sometimes code like:
<strong><h2>This example is copyright of 87android</strong</h2>
which is easily interpreted by popular browsers but it lacks proper nesting of elements. In XHTML we need to nest all elements according to the code structure. For example we can write above code in a proper format for XHTML such as:
<strong><h2>This example is copyright of 87android</h2></strong>
Note: In simple words first opened element should be closed in last after other nesting elements.
e) XHTML is Case Sensitive
Programming in HTML is like paradise for developers. Coding in uppercase or lowercase does not stop the flow of the code in HTML. But in case of XHTML, it requires lowercase coding. For example if we write:
<H1>This example is a copyright of 87android</h1> <!-- Case insensitive code in HTML -->
<h1>This example is a copyright of 87android</h1> <!-- Case Sensitive code in XHTML -->
f) Attributes values should be quoted
In HTML and HTML5 we do not need to quote attribute values. For example if we write:
<table height=200 width=300 border=2>
Above mentioned code will be rendered by browsers easily. But it lacks certain coding standards which is followed by developers in XHTML. The lack of quotes in code can confuse developers with scripting languages. So we must use quotes under transitional markup forms and are required under strict forms like XHTML. For example we can write above code in a proper XHTML format such as:
<table height="200" width="300" border="2">
Note: It doesn’t matter whether we use single or double quotes but we should be consistent in our coding style.
g) Entities should be used for Special Characters
We must escape special characters(< >) with entities like “<” and “>” to create safe web pages. It is also necessary to insert special characters for special quote characters like trademark,currency symbol,copyright and other symbols.
Note: In this article i have mentioned few basic rules for XHTML. Readers are advised to read full documentation of XHTML at W3C website.
Uploaded by: Author