XHTML is HTML written in XML format. Refer to the following Mytour article for a detailed understanding of HTML and XHTML.
Let's delve into the realm of HTML and XHTML
Article Table of Contents:
1. What is XHTML?
2. Why Use XHTML?
3. Differences between HTML and XHTML
4. Declaring XHTML DOCTYPE is Mandatory
5. XHTML Elements Must Be Nested Correctly
6. XHTML Elements Must Have Proper Closing Tags
7. Empty Elements Must Also Be Closed
8. XHTML Elements Must Be Written in Lowercase
9. Attributes Must Be Quoted
10. Converting HTML to XHTML
1. What is XHTML?
- XHTML stands for EXtensible HyperText Markup Language.
- XHTML is similar to HTML but more precise.
- XHTML is defined as an XML application of HTML.
- Major browsers all support XHTML.
2. Why Use XHTML?
Many websites on the internet contain poorly written HTML.
The HTML code below functions well on most web browsers (even when not adhering strictly to HTML rules):
Modern web browsers utilize various technologies. Some browsers are designed for computers, while others run on mobile devices and other small gadgets. Typically, small devices lack resources to interpret poorly marked tag languages.
XML is a tag-based markup language where documents must be precisely marked.
XHTML has evolved by combining the advantages of HTML and XML.
XHTML is a redesigned form of HTML in XML format.
3. Differences between HTML and XHTML
Below are some distinctions between HTML and XHTML:
Document Structure
- Including XHTML DOCTYPE is mandatory.
- The xmlns attribute in html is mandatory.
- The html, head, title, and body tags are mandatory.
XHTML Elements
- XHTML elements must be nested correctly.
- XHTML elements must have proper closing tags.
- XHTML elements must be written in lowercase.
- An XHTML document must have a root element.
XHTML Attributes
- Attribute names must be written in lowercase.
- Attribute values must be quoted.
4. Declaring XHTML DOCTYPE is Mandatory
- In XHTML documents, it is obligatory to use the XHTML DOCTYPE declaration.
- Additionally, the html, head, title, and body elements are mandatory. The xmlns attribute in the html tag must specify the xml namespace for the document.
Example: The example below illustrates an XHTML document with the required tags:
5. XHTML Elements Must Be Nested Correctly
In HTML, SOME elements must be nested correctly within other elements, such as:
In XHTML, ALL elements must be nested correctly within other elements, such as:
6. XHTML Elements Must Have Proper Closing Tags
Example 1: In the example below, the XHTML element lacks a closing tag, resulting in an error:
Example 2: In XHTML, elements must have closing tags as shown below:
7. Empty Elements Must Also Be Closed
Example 1: In this example, the empty element is not closed, leading to an error:
Example 2: We should write it like this:
8. XHTML Elements Must Be Written in Lowercase
Example 1: In this example, XHTML elements are written in uppercase, leading to an error:
Example 2: These elements must be written in lowercase as shown below:
9. Attributes Must Be Quoted
Example 1: In this example, attributes are not quoted, leading to an error:
Example 2: We should write it like this:
10. Converting HTML to XHTML
To convert HTML to XHTML, follow the steps below:
Step 2: Add the xmlns attribute to the html element of each page.
Step 3: Change all element names to lowercase.
Step 4: Close all empty elements.
Step 5: Convert all attribute names to lowercase.
Step 6: Quote all attribute values.
This Mytour article has just introduced you to HTML and XHTML. Additionally, if you have any questions or inquiries like What is URL in HTML?, feel free to leave your thoughts in the comments section below the article. Mytour will address your queries as soon as possible.