Bypass main content
XHTML code (page 2)
This list of rules must be considered as a list of differences between HTML and XHTML. If you have never written HTML documents before, consider this list as a recommendation while you read the HTML tutorials and the HTML reference. You will find that these recommendations present everywhere possible around this site.
- Non-empty tags must always be closed. There is no optional closing in XHTML.
- Valid:
<p>Paragraph 1</p><p>Paragraph 2</p>
- Invalid:
<p>Paragraph 1<p>Paragraph 2
- Empty tags must be correctly closed. To achieve this you can use a normal closing or you can close the tag by putting a slash at the end of the start tag (a space before the slash improves browsers compatibility).
- Valid:
<img src="button.jpg"></img><img src="button.jpg" />
- Invalid:
<img src="button.jpg">
- Tags and attributes names must be lowercase to fit into the XML case-sensitivity (except for the HTML !DOCTYPE tag).
- Valid:
<a href="http://www.htmlquick.com/tutorials.html">Anchor</a>
- Invalid:
<A Href="http://www.htmlquick.com/tutorials.html">Anchor</A>
- The predefined values for some attributes must be lowercase due to the XML case-sensitivity.
- Valid:
<input type="submit" />
- Invalid:
<input type="SUBMIT" />
- The attributes' values must be properly enclosed by quotes (single or double). Quotation is not optional in XHTML.
- Valid:
<span id="id1" class='important'>Text</span>
- Invalid:
<span id=id1 class="important'>Text</span>
- Boolean attributes cannot be abbreviated (using only the attribute's name, without value). As value you must specify the attribute's name.
- Valid:
<button id="button1" disabled="disabled">Execute</button>
- Invalid:
<button id="button1" disabled>Execute</button>
- Nested elements must obey correctly to their hierarchical order.
- Valid:
<span class="double"><strong>Execute</strong></span>
- Invalid:
<span class="double"><strong>Execute</span></strong>
- Block level elements can not be declared as content of in-line elements.
- Valid:
<div class="double"><span>Execute</span></div>
- Invalid:
<span><div class="double">Execute</div></span>
- Some specific elements cannot be declared as content of other specific elements.
- The "a" element must not contain other "a" elements.
- The "pre" element must not contain the "img", "object", "big", "small", "sub" or "sup" elements.
- The "button" element must not contain other "input", "select", "textarea", "label", "button", "form", "fieldset", "iframe" or "isindex" elements.
- The "label" element must not contain other "label" elements.
- The "form" element must not contain other "form" elements.
- All ampersand symbols must be written using its entity name (&), even in URLs.
- Valid:
<a href="buysell.php?id=1&sub=2">Buy & sell</a>
- Invalid:
<a href="buysell.php?id=1&sub=2">Buy & sell</a>
- Character references are case-sensitive.
- Valid:
á - á (for á)
- Invalid:
á - &aAcuTe; (for á)
- The "alt" attribute must always be present in the HTML img tag.
- Valid:
<img src="bird.jpg" alt="A bird flying" />
- Invalid:
<img src="bird.jpg" />
- Commented text will be completely ignored by an XML parser, which means that commenting scripts or style codes to "hide" them from old browsers will be as erasing them. In the other hand, if a script or style code contains a character "&" or "<" they will be processed by the XML parser (as part of the HTML document) giving undesired results. To avoid this problem you can choose to declare them in external files or to use the CDATA block.
- Valid:
<style type="text/css">
<![CDATA[
p { color: blue; }
]]>
</style>
- Invalid:
<style type="text/css">
<!--
p { color: blue; }
-->
</style>
- The "name" attribute has been formally deprecated for the elements a, applet, form, frame, iframe, img, and map, and may be excluded in future versions.
In addition to those declared previously, strict XHTML documents (XHTML 1.0 Strict and XHTML 1.1) should also follow these rules.
- Text must not be defined directly in the body of a document (HTML body tag). Instead insert it into a paragraph, div block, or other element.
- Valid:
<body><p>Text</p></body>
- Invalid:
<body>Text</body>