Rules for writing XHTML code

Source: Internet
Author: User
Tags dashed line end lowercase requires valid
XHTML We first take a look at the code specifications for Web standards. Understanding these specifications can help you take fewer detours and pass code verification as soon as possible.

1. All tags must have a corresponding end tag

Previously in HTML, you could open a number of tags, such as <p> and <li> without necessarily writing the corresponding </p> and </li> to close them. But this is not legal in XHTML. XHTML requires a rigorous structure, and all tags must be closed. If it is a single, unpaired label, add a "/" at the end of the label to close it. For example:

&LT;BR/>

2. All label elements and attributes must be named with lowercase

Unlike HTML, XHTML is sensitive to case,<title> and <TITLE> is a different label. XHTML requires that all labels and attribute names must be in lowercase. For example,:<body> must be written in <body>. Case-by-case inclusions are also not recognized, usually Dreamweaver automatically generated property names "OnMouseOver" must also be modified to "onMouseOver."

3. All XML tags must be nested properly

Also because XHTML requires a rigorous structure, all nesting must be in order, as previously written code:

<p><b></p>/b>

Must be modified to:

<p><b></b>/p>

That is, a layer of nesting must be strictly symmetric.

4. All attributes must be enclosed in quotation marks ""

In HTML, you may not need to enclose attribute values in quotes, but in XHTML they must be quoted. For example:

Must be modified to:

In special cases, you need to use double quotes in the attribute value, which you can use ", single quotes", for example:

<alt= "Say ' Hello '" >

5. Encode all < and & special symbols

Any less than (<), which is not part of the label, must be encoded as & L T;
Any greater-than sign (>), which is not part of the label, must be encoded as & G T;
Any number (&), which is not part of the entity, must be encoded as & a M p;

Note: There are no spaces between the above characters.

6. Assign a value to all properties

XHTML stipulates that all attributes must have a value, and that no value repeats itself. For example:

&LT;TD nowrap> <input type= "checkbox" name= "Shirt" value= "Medium" checked>

Must be modified to:

&LT;TD nowrap= "nowrap" > <input type= "checkbox" name= "Shirt" value= "Medium" checked= "checked" >

7. Do not in the annotation content to make "--"

"--" can only occur at the beginning and end of XHTML annotations, that is, they are no longer valid in the content. For example, the following code is not valid:

<!--here is the annotation-----------here is the annotation-->

Replaces the internal dashed line with an equal sign or a space.

<!--here is the annotation ============ here is the annotation-->

Some of these specifications look strange, but all of this is to make our code have a unified, unique standard for future data reuse.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.