HTML and XHTML differences

Source: Internet
Author: User
Tags cdata

HTML and XHTML

XHTML (extensible Hypertext Markup Language, Extensible Hypertext Markup Language) is the standard for redefining HTML (hypertext Markup Language, Hypertext Markup Language) as an XML application.
Two types of syntax (and) are defined in the HTML5 standard HTML 4.01 XHTML 1 . The standard can be XHTML by defining a special doctype tag, but there is no browser to implement this standard. So the final HTML5 standard overturned the decision.
You can indicate the choice of syntax by using the MIME type (Content-type included in the HTTP request): If you need to use the Xhtml,mime type, you should application/xhtml+xml text/ html not use XHTML if you want.
The appropriate MIME type must exist in the Content-type of the HTTP request. If you only write the MIME type in the HTML tag, as in the case <meta http-equiv=…> , it will still be text/html executed.

HTML Document Specification
HTTP/1.1 200 OKContent-Type: text/html<!DOCTYPE html> lang=en>      <meta charset=utf-8>    <title>HTML</title>    <body>    <p>I am a HTML document</p>  </body>
XHTML documentation Specification
HTTP/1.1 200 OKContent-Type: application/xhtml+xml xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">      <title>XHTML</title>    <body>    <p>I am a XHTML document</p>  </body>
XHTML compatibility

XHTML is currently supported in most browsers, including Firefox, Chrome, Safari, opera, and Internet Explorer (ie 9). (The download dialog for unknown file types is displayed when Internet Explorer 8 and the old browser see an XHTML document with a properly configured XHTML MIME type).
It is important to note that there are many popular JavaScript libraries and development tools that are not supported for XHTML.

The difference between XHTML and HTML

XHTML is an XML application, so XHTNL code specification requirements are stricter than HTML. But for programmers who are accustomed to HTML, there may be some inconveniences, such as a<b < parsing a tag in a comparison statement, causing the code to run as expected. In order to deal with these problems, the following specifications have been gradually introduced:

In 1.JavaScript <And &Should be included in the CDATA code block

In XHTML, the closing character of JavaScript cannot exist outside of the CDATA code block. Example of the following error:

<script type="text/javascript">  var=0;    while (++<10)  {    // ...  }</script>

can be resolved by CDATA a block of code, as in the following example:

<script type="text/javascript"><![CDATA[  var=0;    while (++<10)  {    // ...  }]]></script>

There are other ways to fix the problem, such as replacing it with a < &lt; . However, this reduces the readability of the code, so it is not recommended.

2. Notes <!—— ... ——>The comment content cannot contain double dashes again ——

In XHTML, the <!—— ... ——> contents of a formal comment should not contain double dashes —— , such as the following error example:

<script type="text/javascript"><!--  var i;  var=0;  for=10;>0;--i)  {    += i;  }// --></script>

The contents of the form comments in the example <!—— ... ——> will still be parsed. In the old browser version, experienced developers typically include their content in comments when using inline styles and inline scripting. The following example:

<styletype="Text/css"><!--body{background-color: Blue; Color: Yellow;}-</style><scripttype="Text/javascript"> <!--  varI= 0;  varSum= 0;    for(I= 0;I< Ten; ++I{Sum+=I;  }  Alert(' sum = ' +Sum; // -</script>

This is because inline styles and inline scripts are not yet popular in the old browser version, and the style and script tags are not parsed correctly, but instead directly output the contents of the tag. The following example:

<script>  var=0;  alert(i);</script>

This JS code in the old browser version, will not be executed, but directly output the following content:

var i = 0;alert(i);

However, modern browsers are already starting to support inline styles and inline scripting, so this is generally not the case.

Reference documents MDN--glossary XHTML MDN--properly Using CSS and JavaScript in XHTML Documents

HTML and XHTML differences

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.