XHTML sentence structure is fundamentally the same as HTML language structure and practically all the legitimate HTML components are substantial in XHTML also. In any case, when you compose a XHTML record, you have to give somewhat additional consideration to make your HTML archive consistent to XHTML.
Here are the significant focuses to recollect while composing another XHTML archive or changing over existing HTML report into XHTML record −
- Compose a DOCTYPE revelation toward the beginning of the XHTML report.
- Compose all XHTML labels and qualities in lower case as it were.
- Close all XHTML labels appropriately.
- Home all the labels appropriately.
- Statement all the characteristic qualities.
- Deny Attribute minimization.
- Supplant the name trait with the id Attribute.
- Expostulate the language Attribute of the content tag.
Here is the detail clarification of the above XHTML rules −
DOCTYPE Declaration
All XHTML archives must have a DOCTYPE assertion toward the beginning. There are three sorts of DOCTYPE affirmations, which are talked about in detail in XHTML Doctypes section. Here is a case of utilizing DOCTYPE −
<!DOCTYPE html PUBLIC "-/W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Case Sensitivity
XHTML is case touchy markup language. All the XHTML labels and ascribes should be written in lower case as it were.
<!- - This is invalid in XHTML - >
<A Href="/xhtml/xhtml_tutorial.php">XHTML Tutorial</A>
<!- - Correct XHTML method for composing this is as per the following - >
<a href="/xhtml/xhtml_tutorial.php">XHTML Tutorial</a>
In the model, Href and stay label An are not in lower case, so it is erroneous.
Closing the Tags
Every single XHTML tag ought to have an identical shutting tag, even void components ought to likewise have shutting labels. Here is a model demonstrating substantial and invalid methods for utilizing labels −
<!- - This is invalid in XHTML - >
<p>This passage isn't composed by XHTML punctuation.
<!- - This is likewise invalid in XHTML - >
<img src="/pictures/xhtml.gif" >
The accompanying grammar shows the right method for composing above labels in XHTML. Contrast is that, here we have shut both the labels appropriately.
<!- - This is legitimate in XHTML - >
<p>This section isn't composed by XHTML syntax.</p>
<!- - This is additionally substantial now - >
<img src="/pictures/xhtml.gif"/>
Attribute Quotes
All the estimations of XHTML qualities must be cited. Something else, your XHTML report is accepted as an invalid record. Here is the model indicating punctuation −
<!- - This is invalid in XHTML - >
<img src="/pictures/xhtml.gif" width=250 height=50/>
<!- - Correct XHTML method for composing this is as per the following - >
<img src="/pictures/xhtml.gif" width="250" height="50"/>
Attribute Minimization
XHTML doesn't permit Attribute minimization. It implies you have to expressly express the trait and its worth. The accompanying model shows the distinction −
<!- - This is invalid in XHTML - >
<option selected>
<!- - Correct XHTML method for composing this is as per the following - >
<option selected="selected">
Here is a rundown of the limited characteristics in HTML and the manner in which you have to keep in touch with them in XHTML −
HTML Style | XHTML Style |
---|---|
compact | compact="compact" |
checked | checked="checked" |
declare | declare="declare" |
readonly | readonly="readonly" |
disabled | disabled="disabled" |
selected | selected="selected" |
defer | defer="defer" |
ismap | ismap="ismap" |
nohref | nohref="nohref" |
noshade | noshade="noshade" |
nowrap | nowrap="nowrap" |
multiple | multiple="multiple" |
noresize | noresize="noresize" |
The id Attribute
The id characteristic replaces the name Attribute. Rather than utilizing name = "name", XHTML wants to utilize id = "id". The accompanying model shows how −
<!- - This is invalid in XHTML - >
<img src="/pictures/xhtml.gif" name="xhtml_logo"/>
<!- - Correct XHTML method for composing this is as per the following - >
<img src="/pictures/xhtml.gif" id="xhtml_logo"/>
The language Attribute
The language trait of the content tag is belittled. The accompanying model shows this distinction −
<!- - This is invalid in XHTML - >
<script language="JavaScript" type="text/JavaScript">
document.write("Hello XHTML!");
</script>
<!- - Correct XHTML method for composing this is as per the following - >
<script type="text/JavaScript">
document.write("Hello XHTML!");
</script>
Nested Tags
XHTML tags must be nested properly. Otherwise your document is assumed as an incorrect XHTML document. The accompanying model shows the language structure −
<!- - This is invalid in XHTML - >
<b><i> This content is striking and italic</b></i>
<!- - Correct XHTML method for composing this is as per the following - >
<b><i> This content is intense and italic</i></b>
Element Prohibitions
The accompanying elements are not permitted to have some other component inside them. This disallowance applies to all profundities of settling. Means, it incorporates all the plunging elements.
Element | Prohibition |
---|---|
<a> | It must not contain other <a> elements. |
<pre> | It must not contain the <img>, <object>, <big>, <small>, <sub>, or <sup> elements. |
<button> | It must not contain the <input>, <select>, <textarea>, <label>, <button>, <form>, <fieldset>, <iframe> or <isindex> elements. |
<label> | It must not contain other <label> elements. |
<form> | It must not contain other <form> elements. |
A Minimal XHTML Document
The accompanying model shows you a base substance of a XHTML 1.0 report −
<?xml version="1.0" encoding="UTF-8"?>
<!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/TR/xhtml1" xml:lang="en" lang="en">
<head>
<title>Every record must have a title</title>
</head>
<body>
...your substance goes here...
</body>
</html>
