crus4

crus4

HTML VS XHTML

Table of Contents

What is XHTML?

XHTML stands for EXtensible Hypertext Markup Language. It was developed by World Wide Web Consortium (W3C) in early 2000.

XHTML is pretty much similar to HTML, but it is very strict than HTML. For example in HTML if you don’t close some tags still your code will run. But if you are creating an XHTML page and forget to close some tags, your code will won’t run. Also there are many elements that are mandatory to add in XHTML. These are:

Mandatory to Add in XHTML

Explanation

XHTML – <!DOCTYPE….>

Whenever you create any new XHTML document, It’s mandatory to declare document type.

The XHTML document must also include some mandatory elements like, <html>, <head>, <title> and <body>. The xlmns attribute must also be present in <html> tag. The attribute xlmns specify the xml namespace for the document.

In an Example below this is how a simple XHTML document looks like.

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Title of document</title>
</head>
<body>
<p> main content </p> 

</body>
</html>

Elements in XHTML Must be Properly Nested

Elements in XHTML must always be properly nested. For example:

Right:

<b><i>your text</i><b>

Wrong:

<b><i>your text</b></i> 

All XHTML Elements Must only be in Lowercase

In XHTML, all element names must only be in lowercase. If we write an element name in uppercase the code will won’t run. For example:

Right:

<head>
  <title>
  </title>
</head>

Wrong:

<head>
  <title>
  </title>
</HEAD>

Similarly, all attribute names must be in lowercase only.

Attribute Values in XHTML Must Always be Quoted

Whenever you use an attribute in XHTML, you must Quote it’s value. For example:

Right:

<a href="https://crus4.com/web-development/"> Learn Web Development for free </a> 

Wrong:

<a href=https://crus4.com/python/> Learn Python Programming for free </a> 

XHTML Attribute Minimization is Prohibited

Attribute minimization is prohibited in XHTML. For example:

Right:

<input type="checkbox" name="books" value="Atomic Habits" checked="checked" />
<input type="text" name="lastname" disabled="disabled" />

Wrong:

<input type="checkbox" name="books" value="Atomic Habits" checked />
<input type="text" name="lastname" disabled />

Why Use XHTML?

There are various reasons why we should use XHTML. Some of them are listed below:


Related Posts

HTML Semantic Elements

Images in HTML

HTML Emojis

HTML VS XHTML – crus4