HTML Vs XHTML
XHTML stands for EXtensible HyperText Markup Language.
XHTML is an XML-based version of HTML, which follows strict rules in its markup.
- It is supported by all major browsers.
- It is used to define HTML markup that can be used within an XML application.
Key differences between XHTML and HTML are listed below.
Title | XHTML | HTML |
Doctype declaration <!DOCTYPE> is mandatory. | Yes | Yes |
HTML element <html> must contain "xmlns" attribute. | Yes | No |
HTML elements <html>, <head>, <body>, and <title> are mandatory. | Yes | No |
HTML elements must always be nested properly. | Yes | No |
HTML elements must always be closed. | Yes | No |
HTML elements must always be in lowercase. | Yes | No |
HTML attributes must always be in lowercase. | Yes | No |
HTML attributes must always be quoted. | Yes | No |
HTML attribute minimization is forbidden. | Yes | No |
Examples
Here is an example of an XHTML document, containing all the above-mentioned differences.
- Contains <!DOCTYPE> declaration as needed for an XHTML document.
- HTML element <html> has included the "xmlns" attribute.
- HTML element <html>, <head>, <body>, and <title> are included.
- HTML elements are in lowercase, properly closed, and nested.
- HTML attribute values are quoted properly.
<!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>Page title</title>
</head>
<body>
<h1>Section 1</h1>
<p>This is a paragraph containing a nested <i>italic</i> text and a <br /> line break.</p>
<hr />
<img src="sample.jpg" alt="sample" />
<h2>Input Details</h2>
<input type="text" name="name" disabled="disabled" />
<input type="checkbox" name="vehicle" value="car" checked="checked" />
</body>
</html>
Here is a similar example of an HTML document, containing all the above-mentioned differences.
- Much simpler <!DOCTYPE> declaration.
- HTML element <html> doesn't need "xmlns" attribute.
- HTML element <html>, <head>, <body>, and <title> are included, but they are optional.
- HTML elements are in lowercase, properly closed, and nested, but they can be in any case.
- HTML attribute values are quoted properly.
<!DOCTYPE html>
<html>
<head>
<title>Page title</title>
</head>
<body>
<h1>Section 1</h1>
<p>This is a paragraph containing a nested <i>italic</i> text and a <br> line break.</p>
<hr>
<img src="sample.jpg" alt="sample">
<h2>Input Details</h2>
<input type="text" name="name" disabled>
<input type="checkbox" name="vehicle" value="car" checked>
</body>
</html>
Overall
We now know the key differences between XHTML and HTML, which helps us in writing a better HTML markup.