XHTML is a stricter, more XML-based version of HTML.
Feature | HTML | XHTML |
Definition | Hypertext Markup Language is a markup language used to create web pages and other information that can be displayed in a web browser. | eXtensible Hypertext Markup Language is a markup language that is a stricter version of HTML and conforms to XML syntax. |
Syntax | HTML allows for loose syntax, with end tags and attributes often being optional. | XHTML requires end tags for all elements and attributes to be quoted. |
Document Type Declaration (DTD) | HTML allows for multiple DTDs, including HTML 4.01 and HTML5. | XHTML requires the use of a specific DTD, such as XHTML 1.0 Strict or XHTML 1.1. |
Namespaces | HTML does not support namespaces. | XHTML supports namespaces, allowing for the integration of other XML languages. |
Attributes | HTML allows for the use of deprecated attributes. | XHTML does not allow the use of deprecated attributes and requires all attributes to be lowercase. |
Deprecation | HTML will continue to be supported by web browsers. | XHTML support by web browsers is limited and it is now largely replaced by HTML5. |
Future | HTML continues to evolve, with the latest version being HTML5. | XHTML development has largely been discontinued, with future developments focusing on HTML5. |
XML is a markup language where all documents must be marked up correctly (be "well-formed").
XHTML was developed to make HTML more extensible and flexible to work with other data formats (such as XML). In addition, browsers ignore errors in HTML pages, and try to display the website even if it has some errors in the markup. So XHTML comes with a much stricter error handling.
An XHTML document must have an XHTML <!DOCTYPE> declaration.
The <html>, <head>, <title>, and <body> elements must also be present, and the xmlns attribute in <html> must specify the xml namespace for the document.
Example:
HTML
<!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>
some content here...
</body>
</html>
In XHTML, elements must always be properly nested within each other, like this:
<b><i>Some text</i></b>
Example:
HTML
<b><i>Some text</b></i>
In XHTML, elements must always be closed, like this:
Example:
HTML
<p>This is a paragraph</p>
<p>This is another paragrap
Example:
HTML
<p>This is a paragraph
<p>This is another paragraph
In XHTML, empty elements must always be closed, like this:
Example:
HTML
A break: <br />
A horizontal rule: <hr />
An image: <img src="happy.gif" alt="Happy face" />
Example:
HTML
A break: <br>
A horizontal rule: <hr>
An image: <img src="happy.gif" alt="Happy face">
In XHTML, element names must always be in lowercase, like this:
Example:
HTML
<body>
<p>This is a paragraph</p>
</body>
Example:
HTML
<BODY>
<P>This is a paragraph</P>
</BODY>
In XHTML, attribute names must always be in lowercase, like this:
Example:
HTML
<a href="https://www.w3schools.com/html/">Visit our HTML tutorial</a>
Example:
HTML
<a HREF="https://www.w3schools.com/html/">Visit our HTML tutorial</a>
In XHTML, attribute values must always be quoted, like this:
Example:
HTML
<a href="https://horje.com/html/">Visit our HTML tutorial</a>
Example:
HTML
<a href=https://horje.com/html/>Visit our HTML tutorial</a>
In XHTML, attribute minimization is forbidden:
Example:
HTML
<input type="checkbox" name="vehicle" value="car" checked="checked" />
<input type="text" name="lastname" disabled="disabled" />
Example:
HTML
<input type="checkbox" name="vehicle" value="car" checked />
<input type="text" name="lastname" disabled />
Just replace the https://horje.com and input your website then run to browser.
https://validator.w3.org/nu/?doc=https://horje.com