There are some significant difference between the syntactic rules of HTML and those of XHTML
- Case sensitivity:In HTML, tag and attribute names are case insensitive,meaning that <FORM> ,<form>,and <Form> are equivalent.In XHTML,all tag and attribute names must be in lowecase
- Closing tags:In XHTML,closing tags may be omitted if the processing agent(usually a browser) can infer their presence.For example,in XHTML,paragraph elements often do not have closing tags.The appearance of another opening paragraph tag is used to infer the closing tag on the previous paragraph.For example
<p>
During Spring,flowers are born....
<p>
During Fall ,flowers die...
- In XHTML ,all elements must have closing tags.For elements that do not include content,in which closing tag appears to serve no purpose ,a slash can be included at the end of the opening tag as an abbrevation of the closing tag.For example,the following two lines are equivalent
<input type = "text" name = "address" >
</input>
and
<input type = "text" name ="address"/>
- Quoted attribute values::In HTML,attribute values must be quotes only if there are embedded special characters or whitespace characters.Numeric attribute values are rarely quoted in HTML.In XHTML,all attribute values must be double quoted,regardless of what characters are included in the value
- Explicit attribute values:In HTML,some attribute values are implicit;that is,they need not be explicitly stated.For example,if the border attribute appears in a <table>tag without a value,It specifies a default width border on the table.For example
<table border>
This is illegal in XHTML,in which such an attribute is assigned a string of the name of the attribute.For example, <table border="border">
- Id and name attribute:HTML markup often uses the name attribute as well as id attribute for elements.But In XHTML,the use of id is encouraged,and use of name is discouraged
- Element nesting:Although in HTML has rules against inproper nesting of elements,they are not enforced.Examples of nesting rules are
- an anchor element cannot contain another anchor elent,and a form element cannot contain another form element
- if an element appears inside another element,the closing tag of the inner element nust appear before the closing tag of the outer element
- block elements cannot be nested in inline elements
- text cannot be directly nested in body or form elements
- List elements cannot be directly nested in list elements
- But in XHTML these nesting rules are strictly enforced