# THE DIFFERENCE BETWEEN XML, XHTML AND HTML (with code snippets) ## XML XML (Extensible Markup Language) is a flexible way to structure and store data. It is designed to be simple, readable, and easily used by both humans and computers. It transports and stores data, focusing on what the data is. It does not define how data should be displayed, unlike HTML. **Use Case - code snippet** ``` <?xml version="1.0" encoding="UTF-8"?> <person> <name> Joey Ovey </name> <cohort> Cohort II </cohort> <program> Web2 for Web3 </program> <year> 2025 </year> <organization> Blockfuse Labs </organization> <city> Jos, Nigeria </city> </person> ``` **Key Features:** * Tags are user-defined (<person> and <name> are custom tags). * Requires strict closing of tags. * Case-sensitive (e.g., ``<year>`` is not the same as ``<YEAR>``). * Focused on structure and data representation rather than display. ## XHTML XHTML (Extensible Hypertext Markup Language) is a markup language that is similar to HTML but is based on the XML (Extensible Markup Language) standard. It is a stricter, more well-formed version of HTML, with a few additional rules and requirements. XHTML requires all elements to be properly nested and closed, and all attribute values to be quoted. This means that all tags must be closed, all attributes must have values, and all attribute values must be enclosed in quotes. **Use Case - code snippet** ``` <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>XHTML Example</title> </head> <body> <h1>Hello World, XHTML!</h1> <p>This is a simple XHTML example.</p> <img src="joey.png" alt="logo picture" /> </body> </html> ``` **Key Features:** * All tags must be properly closed (e.g., ``<img />``). * Tag names must be lowercase. * Attributes must have values enclosed in quotes (e.g., alt="Example"). * The document must be well-formed, or it won't render correctly. ## HTML HTML is the standard language for creating web pages. It is designed to display data and focuses on how data looks. It is more forgiving with errors, so browsers often render HTML even with mistakes. **Use case - Code snippet** ``` <!DOCTYPE html> <html> <head> <title>HTML Example</title> </head> <body> <h1>Hello World, HTML!</h1> <p>This is a simple HTML example.</p> </body> </html> ``` **Key Features:** * Tag names are not case-sensitive (``<body>`` is the same as ``<BODY>``). * Closing tags can sometimes be omitted (e.g., ``<img>`` doesn't require a closing tag in traditional HTML). * It's not strict about rules. **General Comparison:** | Features | XML | XHTML | HTML| | ---------------- | --- | ----- | --- | | Purpose | Store/transport data| Display content (strict) | Display content | Syntax rules | Strict | Strict| Clarity | Case-sensitivity | Case-sensitive | Case-sensitive| Not case-sensitive | Tag closure | Mandatory | Mandatory| Optional (for some) | Focus | Data structure | Presentation(clean) | Presentation In summary, if you want a web page with strict syntax rules for better compatibility, use XHTML. If your goal is data transport, XML is better. HTML is sufficient for most web pages. Liked the article? **[Hack-md](https://hackmd.io/)** is a great platform that hosts thousands of great articles like this. Sign up for free today and enjoy!