The difference between HTML and XHTML - Guide to HTML, XHTML Guide

Change Font Size: / / Directory List

The difference between HTML and XHTML

NT22 TutorialHTML TutorialHTML XHTML and the difference is mainly a translation of the w3c Differences with HTML 4 article.

Trackback Address: http://www.nt22.com/xhtml-html/html_xhtml/

XHTML documents must have good integrity of the layout (well-formed)

Good scheduling (Well-formedness) is the XML introduced a new concept. From nature, there must be elements of the end of labels, or must be written in a special way, and must be nested elements.

Despite the overlapping provisions of SGML (overlapping) is illegal, but existing browser generally allowed to overlap.

Correct: nested elements (nested elements)

  <p> NT22 Tutorial <em> XHTML Guide </ em>. </ P> 

Incorrect: cascading elements (overlapping elements)

  <p> NT22 Tutorial <em> XHTML Guide </ p>. </ Em> 

Element and attribute names must be lowercase

For all HTML element and attribute names, XHTML documents must use lowercase. Since XML is case-sensitive. <li> And <LI> such as a different label.

On the non-empty element, we must end the use of labels

Based on SGML in the HTML4 end of the implied meaning of some of the neglected elements allow end labels. Not ignore the end of XML tags. DTD in addition to the elements of the statement is empty, all the elements must be the end of labels.

Correct: the end of the elements (terminated elements)

  <p> NT22 Tutorial Guide to the XHTML. </ P> <p> NT22 Tutorial Guide to the CSS. </ P> 

Incorrect: Before the end of the elements (unterminated elements)

  <p> NT22 Tutorial Guide to the XHTML. <P> NT22 Tutorial Guide to the CSS. 

Attribute value must be in quotation marks

All the attribute value must be in quotes, even in digital form attribute value

Correct: in quotation marks in the attribute value (quoted attribute values)

  <table Rows = "3" /> 

Not correct: not the attribute value in quotation marks (unquoted attribute values)

  <table Rows=3> 

Attribute minimization

XML does not support attributes of the smallest. Attributes - attribute value must complete the write pairs. Like the disabled, checked the properties of this can not be the attribute value specified circumstances arise.

Right: non-minimum of attributes (unminimized attributes)

  <input Checked "checked" => 

Incorrect: Minimum of attributes (minimized attributes)

  <input Checked> 

Air elements

Air elements must have ended labels, or labels must start /> concluded, for example, or <hr> <br/> </ hr>. See HTML compatibility guide HTML Compatibility Guidelines of the information, in order to ensure backward compatibility with HTML 4 user agents.

Correct: the end of empty elements (terminated empty elements)

  <br/> <hr/> 

Error: not the end of the empty label (unterminated empty elements)

  <br> <hr> 

Attribute value in the treatment of blank characters

User agent will be dealt with in accordance with attribute values below XML method Section 3.3.3:

  • By deleting the guide and at the order blank
  • Will be at one or more blank (including newline) into a single space between characters

Script and Style elements

XHTML, and the style elements of the script for # PCDATA contents of the statement form, therefore, <and & be seen as marking the beginning of <and & HTML entities such as XML processor can be used as a separate entity is considered <and &. script and style element will be the contents of hidden markers in the CDATA avoid the expansion of these entities.

  <script> <! [CDATA [... unescaped script content ...]]> </ script> 

CDATA part XML processor identification, the Document Object Model performance in a node. See Section 1.3 of the recommended standard DOM LEVEL 1 [DOM].

Alternative way is to use external script file and style.

SGML exclusion

SGML DTD to the author can specify an element in the Prohibition of the internal elements. Such a prohibition in XML is impossible.

For example, strict DTD HTML 4 "prohibit" any depth of the 'a' element to another 'a' nested elements. In XML can not write these "prohibited." Although these prohibitions can not be defined in the DTD, However, some elements should not be nested. right can not be nested elements Element Prohibitions summed up.

A 'id' and 'name' attribute elements

HTML4 attribute defines the name of the element is a, applet, form, frame, iframe, img and map. HTML4 also introduced id attribute. These two attributes are designed to fragment identifiers used.

In XML, is the fragment identifier ID, each element there can be only one type of ID attribute. Therefore, in XHTML1.0, id attribute is defined as type of ID in order to ensure XHTML1.0 document is structurally sound (well - structured) of XML documents, in the definition of a fragment identifier, XHTML document id attributes must be used, even for those who previously used the name attribute elements. see HTML Compatibility Guidelines to ensure XHTML documents to text / html media types use, these "anchors (anchors)" to backward compatibility.

Note that in XHTML 1.0, the name attribute is not used, and in the subsequent version of XHTML will be deleted.

Finally, the NT22 Tutorial to be a summary:

  • Labels do not overlap, can be nested
  • Tags and attributes must be lowercase
  • Labels must be brought to a conclusion, or to </ p> form the end, or to the end of the form <br />
  • Each property must have the attribute values, and property values in the double quotes
  • Id used by other name:)