Tutorials
CSS
Web Design
XHTML
Javascript
PHP

XHTML
What's XHTML?
XHTML Syntax
XHTML Doctype Definition


More information

(X)HTML Guides
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 attidbutes are lowercase! You can no longer have <H4> or <p>, it must be <h4> 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 compatibale 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">
    <!--

    -->
    </style>


    you now would have the following:

    <style type="text/css">
    /*<![CDATA[*/
    <!--

    -->
    /*]]>*/
    </style>

  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 intorduced 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!

For further information, please contact: http://www.w3.org/TR/xhtml1/


Discuss this in the Forum  

Search HeaphyDesigns



Stored Pages



Change Site Style
Select a style for the site:




More information