Preface
First of all, I would like to ask you a question: do you use uppercase or lowercase letters when writing HTML code? Some people say it is in lower case, others say it is in upper case, and others say it is okay. I would like to say it is better to use lower-case letters for the following reasons: lower-case letters are more readable, and lower-case letters can make your code more compatible with XML code specifications (if you use XHTML, you need to do so ).
Here we introduce XHTML, so what is XHTML, what is its relationship with HTML, and what specifications it has. XHTML is a more rigorous HTML, which is published by W3C and used to help webpage developers transition from HTML to XML. Therefore, you can understand XHTML as an intermediate product of HTML and XML. It not only has the page appeal caused by HTML, but also has the specifications brought about by XML's rigor.
XHTML
Next I will list the things that need special attention when writing XHTML code:
- The root element of the document must be html
- The root element of the document must contain an xmlns attribute to declare the namespace of XHTML)
<HTML xmlns = "http://www.w3.org/1999/xhtml" XML: lang = "en" lang = "en">
- A doctype declaration is required and must be defined before the HTML element.
All XHTML documents must contain the doctype declaration. Likewise, documents must contain common HTML, Head, title, and body elements.
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- All XHTML tags must be in lowercase.
Incorrect syntax: <a href = "/XHTML/xhtml_tutorial.html"> XHTML tutorial </a>
Correct syntax: <a href = "/XHTML/xhtml_tutorial.html"> XHTML tutorial </a>
- All marking elements must follow the "open and closed" principle.
Incorrect syntax:
Correct syntax:
- Attribute values of all elements must be enclosed in quotation marks.
Incorrect syntax:
Correct syntax:
- The omission of some attributes is not allowed, and the attributes must comply with the "key-value" principle.
Incorrect syntax: <option selected>
Correct syntax: <option selected = "selected">
- Use the ID attribute to replace the name attribute
Incorrect syntax:
Correct syntax:
- The language attribute marked by the script is outdated. Do not use
Incorrect syntax:
<Script language = "JavaScript" type = "text/JavaScript">
Document. Write ("Feel free to link to this XHTML tutorial! ");
</SCRIPT>
Correct syntax:
<script type="text/javascript" >
document.write("Feel free to link to this XHTML Tutorial!");
</script>
- Correct use of tag nesting
Incorrect syntax:<b><i> This text is bold and italic</b></i>
Correct syntax:<b><i> This text is bold and italic</i></b>