您的位置:首页 > Web前端 > HTML

HTML与XHTML区别比较

2014-09-12 16:47 281 查看
以下内容翻译自:http://reference.sitepoint.com/html/html-vs-xhtml

1、html大小写不敏感,XHTML敏感,只能用小写标签

2、html标签不一定要求闭合,但是XHTML标签必须闭合
在html中,下面有效:<p>This is my first paragraph.<p>This is my second paragraph.<p>And here’s the last
one..
但在Xhtml中,必须改为:<p>This is my first paragraph.</p><p>This is my second paragraph.</p><p>And here’s
the last one.</p>

3、html甚至允许某些标签(html,head,body,tbody)不需要起始标签,但不建议这么做

4、XHTML要求空元素如img必须加上终止符“/”:<elementname attribute="attributevalue"/>,如果是“application/xhtml+xml”MIME类
型,空元素可以使用start和end tag。如img标签可以写成:<img></img>

5、XHTML要求所有属性的值必须使用引号(单引号和双引号都可以)括起来,如class=“gallery”,不能写成class=gallery。
而在HTML中,属性值可以没有引号

6、XHTML中必须要有<html><head><body>元素,html中可以没有。

7、XHTML可以使用类似<p/>来直接表示元素没有内容,html则不能。

8、XHTML中所有的属性必须写成:属性=“属性值”的形式,而html中允许某些boolean类型的属性只写属性名,不需要写属性值。
如html中表示选中的input元素可以这样写:<input type="checkbox" name="chkNewsletter" checked>;

而在xhtml中必须写成:<input type="checkbox" name="chkNewsletter" checked="checked">.

9、在XHTML中,设置元素内容的语言要用xml:lang属性,在html中用lang属性。

10、在XHTML中,需要在HTTP头部设置正确的MIME类型:"application/xhtml+xml" (this is the best option), "application/xml" (acceptable), or "text/xml" (which isn’t recommended)。

11、XHTML中,text encoding should be set within the XML declaration, not in the HTTP headers (although doing the latter is still
allowed).

元素的属性之间的空格不管多少,只要至少有一个就行。

12、XHTML在处理script和stylesheet也有很大差异:document.write() and document.writeln() do not work in XHTML
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: