---
# System prepended metadata

title: 'The Differences Between XML, XHTML, and HTML (With Examples)'

---

# The Differences Between XML, XHTML, and HTML (With Examples)

Markup languages — XML, HTML, and XHTML—are at the core of how we handle web content and data. While they might look similar at first glance, each serves a unique purpose. 

---

Let’s break them down:

### HTML (HyperText Markup Language)

HTML is the backbone of web pages. It’s used to structure content like text, images, and links. Think of it as the skeleton that tells browsers what to display and how to interpret it.


```
<!DOCTYPE html>
<html>
<head>
    <title>HTML Example</title>
</head>
<body>
    <h1>Welcome to HTML</h1>
    <img src="image.jpg" alt="Sample Image">
    <p>This is a simple HTML document.</p>
</body>
</html>
```
In HTML, you don’t have to follow strict rules, like closing every tag (e.g., `<img>` can remain self-closing).

### XML (eXtensible Markup Language)

XML is all about storing and transporting data. Unlike HTML, it doesn’t focus on how the data looks—it’s all about what the data means. XML is both human- and machine-readable, which makes it ideal for data interchange.

```
<note>
    <to>Tayo</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don’t forget me this weekend!</body>
</note>
```

Key differences from HTML:

- XML is case-sensitive (<Body> and <body> are different).
- Every tag must have a closing tag.
- It doesn’t have predefined tags like `<p>` or `<h1>` — you create your own.


### xHTML (eXtensible HyperText Markup Language)

XHTML is like the stricter, more disciplined sibling of HTML. It combines HTML and XML to create a more structured and well-formed language. If HTML is casual, XHTML is the one that follows all the rules.
    

```
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>XHTML Example</title>
</head>
<body>
    <h1>Welcome to XHTML</h1>
    <img src="image.jpg" alt="Sample Image" />
    <p>This is a strict XHTML document.</p>
</body>
</html>
```

Key differences from HTML:

- All tags must be closed (e.g.,`<img />`).
- Attribute names must be in lowercase.
- Documents must be well-formed (proper nesting of tags, no overlapping).

---

In summary:

- Use HTML for standard web pages.
- Use XML when you need to store and transfer data.
- Use XHTML if you want the discipline of XML combined with HTML for stricter, cleaner coding.