HTML vs XHTML

HTML Tutorial: HTML vs XHTML

Learn the differences between HTML and XHTML, including syntax rules, self-closing tags, and case sensitivity with colorful examples


HTML and XHTML are both markup languages for creating web pages, but they have key differences. HTML is flexible, while XHTML is strict and XML-based.


1️⃣ Syntax Differences

HTML INPUT:


<p>Hello World</p>
<br>
<img src="image.jpg">

XHTML INPUT:


<p>Hello World</p>
<br />
<img src="image.jpg" />

OUTPUT:

Hello World

(Line break)

(Image displayed)

✔️ XHTML requires self-closing tags like <br /> and <img /> ✔️ HTML allows <br> and <img> without closing slash


2️⃣ Case Sensitivity

HTML INPUT:


<TITLE>My Page</TITLE>

XHTML INPUT:


<title>My Page</title>

OUTPUT:

Page Title: My Page

✔️ HTML tags are case-insensitive ✔️ XHTML tags must be lowercase


3️⃣ Closing All Tags

HTML INPUT:


<div>
  <p>Content here</p>

XHTML INPUT:


<div>
  <p>Content here</p>
</div>

OUTPUT:

Content here

✔️ XHTML requires all tags to be properly nested and closed ✔️ HTML is more forgiving with unclosed tags


4️⃣ Attribute Quotes

HTML INPUT:


<img src=image.jpg alt=MyImage>

XHTML INPUT:


<img src="image.jpg" alt="MyImage" />

OUTPUT:

Image displayed with alt text: MyImage

✔️ XHTML requires quotes around all attribute values ✔️ HTML allows unquoted attribute values in many cases


5️⃣ Summary of Differences

Feature HTML XHTML
Tag Case Case-insensitive Lowercase only
Self-closing Tags Optional Required (<br />, <img />)
Attribute Quotes Optional Mandatory
Tag Nesting Flexible Strictly nested

🚀 What’s Next?

👉 HTML Forms

Next lesson will cover:

  • HTML forms for user input
  • Form elements, input types, and attributes
  • Creating interactive web pages

Understanding the differences between HTML and XHTML ensures proper syntax, cross-browser compatibility, and cleaner, maintainable code.

Post a Comment

Share your thoughts! Please be respectful and avoid spam

Previous Post Next Post