Home     SSI Lab     CSS Templates     CSS     Htaccess     Web Design     XHTML

XHTML Tutorials




CSS Templates



Web Design





XHTML Rules and Syntax

Doctype Definition

XHTML documents MUST have a DOCTYPE Declaration and it must validate against one of the three Doctypes, Strict, Transitional or Frameset!

More of this in my XHTML DTD guide.

Rules and Syntax of XHTML

The following are main differences between HTML4.01 and XHTML1.0 and the syntax you must follow to write conforming XHTML documents.

  1. Documents must be well-formed.
    This basically means that all elements must have closing tags or be written in a special form and that all elements must be correctly nested. For example overlapping tags may work in most browsers but are NOT allowed in XHTML. <b><i>This is incorrect</b></i> but <b><i>This IS correct.</i></b>

  2. All element and attribute names must be lower case.
    XML is case-sensitive so because XHTML is an application of XHTML it is important that all elements and attributes are lower case! You can no longer have <h2> or <p>, it must be <h2> and <p>

  3. Non-empty elements must have a closing tag.
    In HTML some elements were not required to have closing tags. For example a paragraph <p> would be closed by the next paragraph to follow, but in XHTML you are required to close all elements so <p> would be closed by </p>

  4. Attribute values must always be quoted
    For example <table width="90%"> is correct but <table width=90%> is incorrect.

  5. Attribute Minimization is not allowed.
    For example <textarea readonly> is incorrect, it must be <textarea readonly="readonly">

  6. Empty Elements must also be closed.
    Where previously we could use <br> or <hr> or <input type="text"> we now need to close these elements with />. So the examples shown become <br/>, <hr/> and <input type="text"/> BUT in order to be backward compatible we add an extra space, so currently you should use: <br />, <hr /> and <input type="text" />

  7. Whitespace in attribute values
    In attribute values, user agents/browsers will strip away one or more leading and trailing whitespace characters from attribute values and leave only a single whitespace character!

  8. Script and Style elements.
    Where previously you had:

    <style type="text/css">


    you now would have the following:

    <style type="text/css">


  9. The id and name attributes.
    In HTML4 the name attribute was defined for the following elements: a, applet, form, frame, iframe, img, and map. HTML4 also introduced the ID attribute. Both name and ID are whats called fragment identifiers. In XHTML1.0 id must be used as the fragment identifier, name will be dropped in future versions of XHTML. Note also: an element can have only 1 id attribute!

Don't forget to visit:


Advertisement Sign up for free to PayBox.me today and get $25 just for joining AND earn up to $20 per day for participating.