bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/HTML/HTML Foundations
HTML•HTML Foundations

HTML Versus XHTML

XHTML is a stricter, more XML-based version of HTML.

What is XHTML?

  • XHTML stands for E X tensible H yper T ext M arkup L anguage
  • XHTML is a stricter, more XML-based version of HTML
  • XHTML is HTML defined as an XML application
  • XHTML is supported by all major browsers

Why XHTML?

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.

If you want to study XML, please read our XML Tutorial .

The Most Important Differences from HTML

  • <!DOCTYPE> is mandatory
  • The xmlns attribute in <html> is mandatory
  • <html>, <head>, <title>, and <body> are mandatory
  • Elements must always be properly nested
  • Elements must always be closed
  • Elements must always be in lowercase
  • Attribute names must always be in lowercase
  • Attribute values must always be quoted
  • Attribute minimization is forbidden

XHTML - <!DOCTYPE ....> Is Mandatory

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

Here is an XHTML document with a minimum of required tags:

<!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>

XHTML Elements Must be Properly Nested

In XHTML, elements must always be properly nested within each other, like this:

Correct

<b><i>Some
 text</i></b>

Wrong

<b><i>Some
 text</b></i>

XHTML Elements Must Always be Closed

In XHTML, elements must always be closed, like this:

Correct

<p>This is a paragraph</p>
<p>This is another paragraph</p>

Wrong

<p>This is a paragraph
<p>This is another paragraph

XHTML Empty Elements Must Always be Closed

In XHTML, empty elements must always be closed, like this:

Correct

A break: <br />
A horizontal rule: <hr />
An image: <img src="happy.gif" alt="Happy face" />

Wrong

A break: <br>
A horizontal rule: <hr>
An image: <img src="happy.gif" alt="Happy face">

XHTML Elements Must be in Lowercase

In XHTML, element names must always be in lowercase, like this:

Correct

<body>
<p>This is a paragraph</p>
</body>

Wrong

<BODY>
<P>This is a paragraph</P>
</BODY>

XHTML Attribute Names Must be in Lowercase

In XHTML, attribute names must always be in lowercase, like this:

Correct

<a href="https://example.com our HTML tutorial</a>

Wrong

<a HREF="https://example.com our HTML tutorial</a>

XHTML Attribute Values Must be Quoted

In XHTML, attribute values must always be quoted, like this:

Correct

<a href="https://example.com our HTML tutorial</a>

Wrong

<a href=https://example.com our HTML tutorial</a>

XHTML Attribute Minimization is Forbidden

In XHTML, attribute minimization is forbidden:

Correct

<input type="checkbox" name="vehicle" value="car" checked="checked" />
<input type="text" name="lastname" disabled="disabled" />

Wrong

<input type="checkbox" name="vehicle" value="car" checked />
<input type="text" name="lastname" disabled />

Validate HTML With The W3C Validator

Put your web address in the box below:

Previous

HTML Uniform Resource Locators

Next chapter

HTML Foundations Practice

Start with HTML Quotation and Citation Elements

This chapter

Overview
56

Lessons

191m

Read time

1. HTML Tutorial2. HTML Introduction3. HTML Editors4. HTML Elements5. HTML Attributes6. HTML Headings7. HTML Paragraphs8. HTML Styles9. HTML Text Formatting10. HTML Comments11. HTML Colors12. HTML RGB and RGBA Colors13. HTML HEX Colors14. HTML HSL and HSLA Colors15. HTML Styles - CSS16. HTML Links17. HTML Links - Different Colors18. HTML Links - Create Bookmarks19. HTML Images20. HTML Image Maps21. HTML Background Images22. HTML <picture> Element23. HTML Favicon24. HTML Page Title25. HTML Tables26. HTML Table Borders27. HTML Table Sizes28. HTML Table Headers29. HTML Table Padding & Spacing30. HTML Table Colspan & Rowspan31. HTML Table Styling32. HTML Table Colgroup33. HTML Lists34. HTML Unordered Lists35. HTML Ordered Lists36. HTML Other Lists37. HTML Block and Inline Elements38. HTML Div Element39. HTML class Attribute40. HTML id Attribute41. HTML Buttons42. HTML Iframes43. HTML JavaScript44. HTML File Paths45. HTML - The Head Element46. HTML Layout Elements and Techniques47. HTML Responsive Web Design48. HTML Computer Code Elements49. HTML Semantic Elements50. HTML Style Guide51. HTML Entities52. HTML Symbols53. Using Emojis in HTML54. HTML Encoding (Character Sets)55. HTML Uniform Resource Locators56. HTML Versus XHTML

On this page

What is XHTML?Why XHTML?The Most Important Differences from HTMLXHTML - <!DOCTYPE ....> Is MandatoryXHTML Elements Must be Properly NestedXHTML Elements Must Always be ClosedXHTML Empty Elements Must Always be ClosedXHTML Elements Must be in LowercaseXHTML Attribute Names Must be in LowercaseXHTML Attribute Values Must be QuotedXHTML Attribute Minimization is ForbiddenValidate HTML With The W3C Validator