HTML
📌 HTML5 and XHTML
🔹 What Are HTML and XHTML?
HTML (HyperText Markup Language)
- HTML is the standard language used to create and structure web pages.
- 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)
- XHTML is a stricter version of HTML based on XML standards.
- It enforces rules such as: all tags must be properly closed, tag names must be lowercase, and all attribute values must be quoted.
- 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:
- All tags are lowercase.
- Empty tags like
<img>and<br>must be self-closed (/>) - Attribute values always need quotes
- 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.
