After introducing you to how to correctly use javascript and css in xhtml, web design continues to bring you 16 guidelines for xhtml compatibility with html!
1. Avoid declaring the page as xml type, and use the utf-8 or utf-16 character sets on the page.
2. Add a slash/ before the ending character > of the empty element label (the label cannot be used to contain content), such as: <br />, <hr />, etc.
3. When a non-empty element (this label is used to contain content, such as title, paragraph) is empty, give it a blank character, and do not use an ending method like an empty element, such as: When a p tag without content, please write: <p> </p> instead of <p />.
4. When <, &, ]]> or two consecutive horizontal bars appear in your style and scripts content, please use external files to introduce them.
5. Avoid breaking lines or multiple spaces in element attribute values.
6. Do not include more than one isindex element in the head part of the document (preferably not used). This element is not recommended.
isindex: Makes the browser display a dialog box that prompts the user to enter a single line of text.
In html 4, this element is deprecated, and the input element is recommended. The tagname property of isindex will return input.
This element is a block element, and this element needs to close the 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 language to an element, please use the lang and xml:lang attributes, the value of xml:lang has higher priority.
8. Please use the id attribute as element identifier, avoid using the name attribute, especially on these elements, it is more disapproving of using the name attribute as their identifier: a, applet, form, frame, iframe, img, map.
9. Define the document character set for the page and define the character set for the XML document.
<?xml version=1.0 encoding=utf-8?>
Define character set for xhtml
<meta http-equiv=content-type content=text/html; charset=utf-8 />
10. Please use the attribute name for the boolean type element attribute value, such as: checked=checked. The boolean type elements include: compact, nowrap, ismap, declare, noshade, checked, disabled, readonly, multiple, selected, noresize, defer
11.html4 and xml document object models specify that html element and attribute names return uppercase format. Elements and attribute names in xhtml return to lowercase format.
12. Use & to replace the & symbol in the property value, such as:
http://www.w3cgroup.com/default.asp?cateid=2&page=2
Better than the following:
http://www.w3cgroup.com/default.asp?cateid=2&page=2
13. In xhtml, css style tag style and attribute names must be lowercase;
In the html table, tbody will be automatically filled during parsing, but not in the xml. Therefore, 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 style elements when parsing XML documents? In html4 and xhtml, the style element can be used to define style rules in the document. In xml, the xml stylesheet is used to define style rules. In order to be compatible with this rule, if you need to use the style element when parsing the XML document, the style element needs to use the id attribute as an identifier, and there must be an xml stylesheet to refer to 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 compatible 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 be illegal in XML. For example, in html, the page feed character (formfeed character u+000c) is parsed into spaces, while in xhtml, it becomes illegal due to the character definition of xml.
16 Note that the special characters ' (ellipsis, u+0027) are introduced in xml1.0, but they do not appear in html. If you use "replace '" to use "replace '" to use it to use it in html4.
Translated by http://www.w3cgroup.com, please indicate the source when reprinting!
See: http://www.w3.org/tr/xhtml1/#guidelines