Summary of 16 XHTML1.0 and HTML Compatibility Guidelines

Summary of 16 XHTML1.0 and HTML Compatibility Guidelines

1. Avoid declaring the page as XML type . The page should use UTF-8 or UTF-16 character set.

2. Add a slash / before the end character > of an empty element tag (a tag that cannot contain content) , such as: <br />, <hr />, etc.

3. When a non-empty element (this tag is used to contain content, such as a title or paragraph) has empty content, give it a blank character instead of using the same ending method as an empty element . For example, when there is a P tag with no content, please write: <p> </p> instead of <p />.

4. When <, &, ]]> or two consecutive hyphens -- appear in your style and scripts content, please use external files to import them.

5. Avoid line breaks or multiple spaces in element attribute values.

6. Do not include more than one isindex element in the head section of the document (it is best not to use it). This element is not recommended.
isindex: Causes the browser to display a dialog box prompting the user to enter a single line of text.
In HTML 4, this element was deprecated in favor of the INPUT element. The tagName property of isIndex will return input.
This element is a block element and requires a closing tag.
The following example uses the ISINDEX element to replace the default prompt:
<isindex prompt="Enter the index keyword to search" />

7. When you want to specify the language for an element, use the lang and xml:lang attributes . The value of xml:lang takes precedence.

8. Please use the id attribute as the element identifier and avoid using the name attribute . It is especially not recommended to use the name attribute as their identifier on the following elements: a, applet, form, frame, iframe, img, map.

9. Define the document character set for the page . Use <?xml version="1.0" encoding="UTF-8"?> to define the character set for XML documents, and use <meta http-equiv="Content-type" content="text/html; charset=UTF-8" /> to define the character set for XHTML.

10. For Boolean type element attribute values, please use the attribute name , such as checked="checked". Boolean type elements include: compact, nowrap, ismap, declare, noshade, checked, disabled, readonly, multiple, selected, noresize, defer

11. HTML4 and XML Document Object Model specify that HTML element and attribute names are returned in uppercase format. In XHTML, element and attribute names are returned in lowercase.

12. Use &amp; to replace the ampersand in the attribute value

13. In XHTML, CSS style tags and attribute names must be lowercase ;
In HTML tables, tbody will be automatically completed when parsing, but in XML it is not, so you need to add the tbody element yourself if you use it in the CSS selector;
When CSS selects an element with an id attribute, use the # selector ;
When CSS selects an element with a class attribute, use the . selector ;

14. How to use the Style element while parsing an XML document? In HTML4 and XHTML, the style element can be used to define style rules in a document. In XML, the XML stylesheet is used to define style rules. To be compatible with this rule, if you need to use the style element when parsing an XML document, the style element needs to use the id attribute as an identifier, and there must be an XML stylesheet to reference it , such as:

<?xml-stylesheet href="http://www.w3.org/StyleSheets/TR/W3C-REC.css" type="text/css"?>
<?xml-stylesheet href="#internalStyle" type="text/css"?>
<!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" xml:lang="en" lang="en">
<head>
<title>An internal stylesheet example</title>
<style type="text/css" id="internalStyle">
code {
color: green;
font-family: monospace;
font-weight: bold;
}
</style>
</head>
<body>
<p>
W3CGroup introduces 16 guidelines for compatibility between XHTML and HTML!
<code>http://www.w3cgroup.com/article.asp?id=252</code>.
</p>
</body>
</html>


15. Pay attention to whitespace characters in HTML and XML . Some characters that are legal in HTML documents may not be legal in XML. For example, in HTML, the formfeed character (U+000C) is parsed as a space, but in XHTML, it becomes illegal due to XML's character definition.

16 Note that the special character &apos; (ellipsis, U+0027) was introduced in XML1.0 but did not appear in HTML. Replacing &apos; with &#39; allows it to be used in HTML4.

<<:  Detailed explanation of Docker Secret management and use

>>:  Pure CSS header fixed implementation code

Recommend

Introduction to HTML page source code layout_Powernode Java Academy

Introduction to HTML page source code layout This...

Four ways to create objects in JS

Table of contents 1. Create objects by literal va...

How to generate Vue user interface by dragging and dropping

Table of contents Preface 1. Technical Principle ...

Quick understanding and example application of Vuex state machine

Table of contents 1. Quick understanding of conce...

Complete steps to reset the root user password in mysql8

Preface Recently, many new colleagues have asked ...

Design theory: the basics of font design

<br />Words are the inevitable product of hu...

Steps to package and release the Vue project

Table of contents 1. Transition from development ...

MySQL Learning: Three Paradigms for Beginners

Table of contents 1. Paradigm foundation 1.1 The ...

CSS draw a lollipop example code

Background: Make a little progress every day, acc...

Windows 10 + mysql 8.0.11 zip installation tutorial detailed

Prepare: MySQL 8.0 Windows zip package download a...

How to create a simple column chart using Flex layout in css

The following is a bar chart using Flex layout: H...

Vue makes div height draggable

This article shares the specific code of Vue to r...

JavaScript Composition and Inheritance Explained

Table of contents 1. Introduction 2. Prototype ch...

Analysis of the principles and usage of Docker container data volumes

What is a container data volume If the data is in...