XHTML (Extensible Hypertext Markup Language) is a stricter and more XML-compliant version of HTML. It adheres to the syntax rules of XML and has some additional requirements compared to HTML. Here's a basic comparison between HTML and XHTML tags:
<br>
, <img>
, and <input>
.<br>
, <img>
, and <input>
.<br />
, <img />
, <input />
).<html>
element, and they should be served with the correct MIME type, such as application/xhtml+xml
.Here's an example of a simple HTML document:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>HTML Example</title>
</head>
<body>
<h1>Hello, HTML!</h1>
<p>This is an example of HTML.</p>
</body>
</html>
And here's the same document written in XHTML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title>XHTML Example</title>
</head>
<body>
<h1>Hello, XHTML!</h1>
<p>This is an example of XHTML.</p>
</body>
</html>
In summary, while HTML is more lenient and forgiving, XHTML imposes stricter rules to ensure well-formed documents that are more compatible with XML tools and technologies.