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.

Related Posts
XHTML Tutorial

The XHTML tutorial explains both the basics and more advanced ideas about XHTML. Our XHTML tutorial is made for both Read more

About XHTML

  EXtensible HyperText Markup Language is what XHTML is short for. It is a mix of the HTML language and Read more

XHTML Events

  When you go to a website, you can click on text, images, and links, move your mouse over things, Read more

Doctypes in XHTML

  Descriptions of Document Types come in three flavours (DTDs). The XHTML Transitional standard is the most user-friendly and widespread. Read more

Attributes of XHTML

  Some XHTML attributes are the same for all XHTML tags and go with them. There are three different kinds Read more

How to Disable a Link Using CSS Styling Links

How to visually hide an element with CSS? What is the purpose of the hidden attribute in HTML? How to Read more

Scroll to Top