📌 HTML5 and XHTML

🔹 What Are HTML and XHTML?

HTML (HyperText Markup Language)

  1. HTML is the standard language used to create and structure web pages.
  2. It is forgiving of small mistakes, like unclosed tags or minor syntax errors, so pages usually still display even if there are errors.

XHTML (eXtensible HyperText Markup Language)

  1. XHTML is a stricter version of HTML based on XML standards.
  2. It enforces rules such as: all tags must be properly closed, tag names must be lowercase, and all attribute values must be quoted.
  3. XHTML does not tolerate errors; even small mistakes can prevent a page from loading correctly.

🔹 Key Differences Between HTML and XHTML

Feature HTML XHTML
Case Sensitivity Tag names and attributes are case-insensitive (<body> = <BODY>) All tags and attributes must be lowercase
Closing Tags Some tags can be left unclosed (<br>, <img>) All tags must be closed (<br />, <img />)
Attribute Values Quotes around attribute values are optional (<a href=link.html>) Quotes are mandatory (<a href="link.html">)
Error Handling Tolerates errors Errors may prevent the page from displaying
Document Type <!DOCTYPE html> XHTML requires a specific DOCTYPE, e.g., <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">

🔹 Examples of HTML vs XHTML

HTML Example (Flexible)

HTML

<!DOCTYPE html>
<html>
    <head>
        <title>HTML Page</title>
    </head>
    <body>
        <h1>Hello World</h1>
        <p>This is an HTML paragraph.</p>
        <img src="image.jpg" alt="Image">
        <br>
        <a href=link.html>Link</a>
    </body>
</html>
                

XHTML Example (Strict)

HTML

<!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" lang="tr">
    <head>
        <title>XHTML Page</title>
        <meta charset="UTF-8" />
    </head>
    <body>
        <h1>Hello World</h1>
        <p>This is an XHTML paragraph.</p>
        <img src="image.jpg" alt="Image" />
        <br />
        <a href="link.html">Link</a>
    </body>
</html>
                

Key Points in XHTML:

  1. All tags are lowercase.
  2. Empty tags like <img> and <br> must be self-closed (/>)
  3. Attribute values always need quotes
  4. XHTML requires the <xmlns> attribute for the HTML namespace.
  • Summary

  • HTML is flexible, forgiving, and good for quick development.
  • XHTML is strict, XML-based, and ensures cleaner and more standardized code.
  • Modern HTML5 combines the flexibility of HTML with some XHTML conventions, but strict XML rules are not strictly enforced anymore.