Use code to learn the difference between XHTML and HTML

Source: Internet
Author: User
Tags empty end lowercase prepare
Xhtml

By starting to write strict HTML, you can prepare for XHTML.

How to prepare for XHTML

XHTML is not much different from the HTML 4.01 standard.

So it's a good start to upgrade your code to 4.01. The HTML 4.01 Reference manual will help you do this.

In addition, you should immediately write HTML code in lowercase letters, and never develop a bad habit of ignoring similar </p> tags.

Wish you can be happy to code!

The main differences are:

    • XHTML elements must be nested correctly.
    • XHTML elements must be closed.
    • Label names must be in lowercase letters.
    • XHTML documents must have root elements.

Elements must be nested correctly

In HTML, some elements can be nested incorrectly like this:

<b><i>this text is bold and italic </b> </i>

In XHTML, all elements must be nested correctly like this:

<b><i>this text is bold and italic</i></b>

Tip: An easy mistake in a nested list is to forget that the internal list must reside in the LI element, as follows:

This is wrong:

<ul>  <li>Coffee</li>  <li>Tea    <ul>      <li>black tea</li>      < Li>green tea</li>    </ul>  <li>Milk</li></ul>

That's right:

<ul>  <li>Coffee</li> tea  <li>    <ul>      <li>black tea</li>      <li>green tea</li>    </ul>  </li>  <li>Milk</li></ul>

Note: In the case of the correct code, we insert a </li> tag after </ul>.

XHTML elements must be closed

A non-empty label must use an end tag.

This is wrong:

<p>This is a paragraph the this is <p> another paragraph

That's right:

<p>This is a paragraph the this is </p> <p> another paragraph</p>

Empty labels must also be closed

An empty label must also use an end tag, or its start tag must use the /> end.

This is wrong:

A break: <br>a Horizontal rule: 

That's right:

/>/>/>

XHTML elements must be lowercase

XHTML specification Definition: Tag names and attributes are case-sensitive.

This is wrong:

<BODY><P>This is a paragraph</P></BODY>

That's right:

<body><p>This is a paragraph</p></body>

XHTML documents must have a root element

All XHTML elements must be nested within the



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.