XHTML syntax is fundamentally the same as HTML syntax structure and all valid HTML elements also get validate in XHTML too. If user composing a XHTML record, user need to give careful consideration to make the HTML document consistent to XHTML.
Following are the some points to remember while constructing XHTML Document.
- Doctype Declaration
- Case sensitive
- Closing tags
- Attributes Quotes
- The id Attribute
- The Language Attribute
- Nested Tags
Doctype Declaration
Similar to HTML All XHTML documents must present a DOCTYPE declaration at the top. There are three sorts of DOCTYPE declarations thise are alreday shown in the example below demonstrates the Doctype.
[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
[/html]
Case sensitive
XHTML is case touchy markup dialect. All XHTML labels and credits should be composed in lower case as it were.
[html]
<!-- This is invalid in XHTML -->
<A Href="/xhtml/xhtml_tutorial.html">XHTML Tutorial</A>
<!-- Correct XHTML way of writing this is as follows -->
<a href="/xhtml/xhtml_tutorial.html">XHTML Tutorial</a>
[/html]
Closing tags
Every XHTML tag ought to has a equal closing tags, even empty elements should maintain closing tags. The snippet below demonstrates the proper and un proper way of using tags.
[html]
<!-- This is invalid in XHTML -->
<p>This paragraph is not written according to XHTML syntax.
<!-- This is also invalid in XHTML -->
<img src="/images/xhtml.gif" >
[/html]
The snippet below demonstrates the proper way of using tags.
[html]
<!-- This is valid in XHTML -->
<p>This paragraph is not written according to XHTML syntax.</p>
<!-- This is also valid now -->
<img src="/images/xhtml.gif" />
[/html]
Attributes Quotes
Each values of XHTML attribute can be Quoted.Otherwise,the document is treated as an invalid. The snippet below demonstrates the syntax.
[html]
<!-- This is invalid in XHTML -->
<img src="/images/xhtml.gif" width=250 height=50 />
<!-- Correct XHTML way of writing this is as follows -->
<img src="/images/xhtml.gif" width="250" height="50" />
[/html]
The id Attribute
The id attribute can replaces the name characteristic. Rather than utilizing name = "name", XHTML likes to utilize
id = "id". The snippet below demonstrates the id attribute.
[html]
<!-- This is invalid in XHTML -->
<img src="/images/xhtml.gif" name="xhtml_logo" />
<!-- Correct XHTML way of writing this is as follows -->
<img src="/images/xhtml.gif" id="xhtml_logo" />
[/html]
The Language Attribute
The language attribute of the script tag is deprecated. The snippet below demonstrates language attribute.
[html]
<!-- This is invalid in XHTML -->
<script language="JavaScript" type="text/JavaScript">
document.write("Hello XHTML!");
</script>
<!-- Correct XHTML way of writing this is as follows -->
<script type="text/JavaScript">
document.write("Hello XHTML!");
</script>
[/html]
Nested Tags
User should settle all the XHTML tags appropriately. Generally user document is an incorrect XHTML document. The snippet below demonstrates the Nested tags.
[html]
<!-- This is invalid in XHTML -->
<b><i> This text is bold and italic</b></i>
<!-- Correct XHTML way of writing this is as follows -->
<b><i> This text is bold and italic</i></b>
[/html]