XHTML Syntax Rules

XHTML Syntax Rules

XHTML follows the following syntax

·         Documents in XHTML must always be well-formed

All XHTML Document can have only one root element that is <html>all other elements should be nested within the root element. There will be only one parent called a root element which can have its children(sub elements) nested within it.

  • Sub elements must be in pairs and correctly nested within their parent element. The basic document structure is:
(doctype)
<html xmlns=”http://www.vyom.co.in/xhtml“>
<head>
<title>…</title>
… </head>
<body>… </body>
</html>

Notice the (doctype) and the “xmlns” attribute on the opening html tag. You should also include a character set meta tag in the <head> element.


·         XHTML elements must be properly nested

Wrong:

<p>This is our site <em>paragraph.</p></em>

Right:

<p>This is our site <em>paragraph.</em></p>

·         Since XML is case-sensitive. Tag names must be in lowercase.

Wrong:

<PRE>Some preformatted text.</PRE>

Right:

<pre>Some preformatted text.</pre>

·         All Attributes that are used here must be in lower case

Wrong:

<a HREF=”http://www.vyom.co.in“>

Right:

<a href=”http://www.vyom.co.in“>

·         All elements must be closed

This includes elements that traditionally do not contain any content, such as images, form inputs, meta tags, etc.

Wrong:

<p>Welcome to vyom.
<p>This is our website

Right:

<p>Welcome to vyom..</p>
<p>This is our website.</p>
Elements which dont have closing tags must be closed with slash inside the tag.
<br> becomes <br />
<hr> becomes <hr />
<input>becomes <input />

·         All attributes values must be quoted

Wrong:

<a href=http://www.vyom.co.in>example link</a>

Right:

<a href=”http://www.vyom.co.in“>example link</a>

·         Attribute minimization is forbidden

Wrong:<input checked />

Right:

<input checked=”checked” />

·         All image tags should have “alt” attributes.

Wrong:<img src=”kitten.jpg” />

Right:

<img src=”kitten.jpg” alt=”an evil kitten” />


·         The “id” attribute and the “name” attribute-

Element ids which should be uniqe eventually will replace element names.For now, to ensure backword-compatibility it is recommended to use both,for example, many of the form fields are accessed by their names. In cascading style sheets and various scripting languages Ids are used .

<img src=”kitty.jpg” alt=”an evil kitten” /><img src=”kitty.jpg” alt=”an evil kitten” />

·         The XHTML DTD defines mandatory elements

DOWNLOAD SOLUTION HERE