(X)HTML compliance in short

Alexander edited this page Apr 23, 2015 · 3 revisions
Clone this wiki locally
  • tag and attribute names must be in lower case;
  • for non-empty elements, end tags are required
<!-- BAD -->
    <p>paragraph 1<p>paragraph 2
<!-- GOOD -->
    <p>paragraph 1</p><p>paragraph 2</p>
  • attribute values must always be quoted
<!-- BAD -->
    <td rowspan=3>
<!-- GOOD -->
    <td rowspan="3">
  • attribute-value pairs must be written in full
<!-- BAD -->
    <dl compact>
<!-- GOOD -->
    <dl compact="compact">
  • tag for empty element must end with " />"
<!-- BAD -->
    <hr> <br>
<!-- GOOD -->
    <hr /> <br />
  • Include a space before the trailing / and > of empty elements, e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />
  • do not use empty instance of an element whose content model is not EMPTY (for example, an empty div or paragraph)
<!-- BAD -->
    <div></div>
<!-- GOOD -->
    <div> </div>  <!-- white space inside! -->
<!-- GOOD -->
    <div>
    </div>      <!-- line-break between start and end tags -->
  • only five "standardised" named entities are allowed: &amp; &quot; &lt; &gt; &apos;
    Use numeric entities in all other cases (i.e. &#160; in place of &nbsp;, &#169; in place of &copy;, etc.)
  • internal scripts content should be wrapped by //<![CDATA[ and //]]>, i.e.
<script>
//<![CDATA[
    // my scipt here
    do_something();
    // ...
//]]>
</script>