HTML and XHTML differences

Source: Internet
Author: User
Tags closing tag lowercase

This article focuses on the differences between HTML and XHTML. In simple terms, XHTML can be considered an XML version of HTML, and XHTML syntax requires more rigor to conform to XML requirements.

The following are some of the major differences between XHTML vs. HTML:

    • XHTML requires proper nesting
    • XHTML all elements must be closed
    • XHTML is case sensitive
    • XHTML attribute values are in double quotes
    • XHTML replaces the Name property with an id attribute
    • Processing of XHTML special characters

XHTML requires proper nesting

The following are the correct nesting:

<p> Web Teaching Network <strong> Update speed is the fastest </strong>. </p>

The following are the wrong nesting:

<p> Web Teaching Network <strong> Update speed is the fastest </p></strong>.

XHTML all elements must be closed

In HTML, such as <p>,<li> tags, you may not write </p>,</li>, but in XHTML, you must require a write-close tag (Closing tag).

Like what:

<p> Web Teaching network is very serious.

should be written:

<p > Web Teaching Network is very serious. </p>

Handling empty elements

Some empty elements, written in XHTML, are preceded by spaces and slashes before ">". such as <br>, should be written <br/>.

The following is an example of an empty element:

<br/>

<link rel= "stylesheet" href= "/styles/webjx.css" type = "Text/css"/>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>

XHTML is case sensitive

HTML is case-insensitive, but XHTML is case-sensitive.

The XHTML syntax requires more rigor. Take a positive look at the problem.

All markup and attributes for XHTML are lowercase.

Like what:

should be written:

XHTML attribute values are in double quotes

The situation is different. Do not force attribute values to double quotes?

HTML does not force an attribute value to be enclosed in double quotes. For example, you can write:

<table cellspacing = 0>
<input checked >

A few big differences: HTML 4.01 is really no different than that?

But in XHTML, it should be written:

<table cellspacing = "0" >
<input checked = "Checked"/>

XHTML replaces the Name property with an id attribute

Many elements of HTML, such as a,applet,frame,iframe,img and map, have the name attribute. It is to be abolished in XHTML and replaced with the id attribute.

Like what:

should be written:

Processing of XHTML special characters

& should be written as &amp; in XHTML.

For example: all of the markup and attributes for XHTML are lowercase.

Like what:

You & Me

should be written:

You &amp; Me

And if you embed Jav ascript code, in XHTML you should write:

<script type= "Text/javascript" >//<! [cdata[
...
]]></script>

The angle of the browser

The above is from the point of view of the Agreement standard to see this problem. If you look at the problem from a browser perspective, the situation is different.

Think about what the browser would do if the XHTML was not strictly written. Is it going to pop up a dialog box that says, "the developers of this site are not skilled, write not authentic XHTML files, I do not show"? Obviously, if the browser is made this way, there is no use in paying the money.

From a browser perspective on the above several different, roughly the following test results (IE and Firefox I have tested):

    • XHTML requires proper nesting: if you don't have nested, the browser will try to help you nest.
    • XHTML all elements must be closed: if you do not close, the browser will try to help you off.
    • XHTML is case-sensitive: you have to write uppercase, and browsers help you convert to lowercase.
    • Attribute values in double quotes: You must not add, the browser to help you add.
    • Special character processing: you & Me or you &amp; Me or the browser can read.
    • Replace the Name property with the id attribute: You can use name as well.

XHTML should be written in &amp;. The following are the correct nesting.

If you start using DocType as XHTML in your document, you need to be aware of it. When assigning CSS to Tag with class, it is case-sensitive. For example, you define a CSS as follows,

<style>
. Hello {...}
</style >

And when you use it, it's written,

<p class= "Hello" > ...

And when you use it, write it, if you look at it from a browser's point of view.

That CSS is not going to be used. It's a good thing to take a positive look at this issue so that you can name the Style with more names.

The future of XHTML standards

From the perspective of the standard-makers, the XHTML standard is an attempt to make the HTML specification a strict XML format, which inevitably leads to the result that upgrades from HTML to XHTML result in reduced standard fault tolerance. It's good to write your own web-source files strictly, but a standard is not going to require browsers to reduce their fault tolerance.

The XHTML 1.0 Standard is compatible with HTML 4.01, which is a good protocol to allow developers to write code with some tools to check the legality of the Code, although for users, the production of web pages and HTML 4.01 is no different. Using XHTML 1.0 is a good choice for you to write new pages.

The XHTML 1.1 standard requires that browsers no longer support the original fault tolerance, a typical example of a standard-setting obsession, which is academically pure, but a stiff, clumsy, unreasonable standard for browsers. So at present all developed by the Human browser is not in accordance with the so-called Pure XHTML 1.1 standard, your code as long as the browser can read, he will be very good display, and do not jump out of the frame error.

Should be written:: Should be written: The following is XHTML relative!

From the trend of development, a standard without the browser to obey, is tantamount to meaningless standards. From the perspective of the browser implementation, the new protocol can only expand the ability to increase fault tolerance on the basis of the original HTML, but not the ability to reduce fault tolerance. So in the new deal, only the part that expands the capacity to increase fault tolerance will be adopted, while the rest is merely theoretical.

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.