Syntax of XHTML

The syntax of XHTML is substantially similar to that of HTML, and all valid HTML components are likewise valid in XHTML. However, because XHTML is case sensitive, you must exercise caution when constructing an XHTML page to ensure that your HTML document is XHTML compliant.

While creating a new XHTML document or converting an old HTML document to XHTML, keep the following points in mind:

  • A DOCTYPE must be assigned to all documents.
  • All tags must be written in lower case.
  • All documents must be correctly formatted.
  • Every tag must be closed.
  • All attributes must be appropriately added.
  • The name attribute has been updated.
  • Attributes cannot be abbreviated.
  • All tags must be nesting appropriately.

Declaration of DOCTYPE

All XHTML documents must begin with a DOCTYPE declaration. There are three sorts of DOCTYPE declarations:

Transitional Strict Frameset

Here’s an example of how to use DOCTYPE.

 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”

Tags must be written in lower case.

The markup language XHTML is case-sensitive. As a result, all XHTML tags and attributes must be in lower case.

<!– In XHTML its Invalid –>
<A Href=”/xhtml/about-xhtml/”>XHTML Tutorial</A>
<!– In XHTML its Valid –>
<a href=”/xhtml/about-xhtml/”>XHTML Tutorial</a>

Closing Tags are required

An XHTML document must have a closing tag. Even empty elements require ending tags. Here’s an example:

<!– In XHTML its Invalid –>
<p>This paragraph is not written according to XHTML syntax.
<!– In XHTML its Valid –>
<img src=”https://www.coderazaa.com/images/xhtml.png” >

<!– In XHTML its Invalid –>
<p>This paragraph is not written according to XHTML syntax.</p>
<!– In XHTML its Valid –>
<img src=”https://www.coderazaa.com/images/xhtml.png” />

 

Quotations with Attributes

The values of all XHTML attributes must be quoted. Otherwise, your XHTML document would be considered invalid.

Consider the following example:

<!– In XHTML its Invalid –>
<img src=”https://www.coderazaa.com/images/xhtml.png” width=250 height=50 />
<!– In XHTML its Valid –>
<img src=”https://www.coderazaa.com/images/xhtml.png” width=”250″ height=”50″ />

Minimization of Attributes

You cannot decrease properties in XHTML. The characteristic and its value must be stated unambiguously.

Consider the following example:

 

<!– In XHTML its Invalid –>
<input text>
<!– In XHTML its Valid –>
<input type=”text”>

A list of reduced HTML properties and how to write them in XHTML.

 

The id Attribute

The id attribute replaces the name attribute. XHTML favours id = “id” instead of name = “name”.

Consider the following example:

<!– In XHTML its Invalid –>
<img src=”https://www.coderazaa.com/images/xhtml.png” name=”xhtml_logo” />
<!– In XHTML its Valid –>
<img src=”https://www.coderazaa.com/images/xhtml.png” id=”xhtml_logo” />

The language attribute

The language attribute of the script tag is deprecated in XHTML, so you must use the type attribute instead.

Consider the following example:

<!– In XHTML its Invalid –>
<script type=”text/JavaScript” language=”JavaScript” >
document.write(“First XHTML example!”);
</script>
<!– In XHTML its Valid –>
<script type=”text/JavaScript”>
document.write(“First XHTML example!”);
</script>

Nested Tags

XHTML tags must be properly nested. Otherwise, your document is judged to be a bad XHTML document.

Consider the following example:

<!– In XHTML its Invalid –>
<b><i> Loream ipsum is dummy text.</b></i>
<!– In XHTML its Valid –>
<b><i> Loream ipsum is dummy text.</i></b>

Prohibited Elements

The following elements are not permitted to contain any other element. This is true for all descending elements.

People also search
Scroll to Top