开发者

Is this page coded incorrectly for proper HTML?

Learning a bit about the differences between XHTML and HTML, I looked at the source of one of our pages:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

Is this correct? Seems like it’s trying to be a HTML page, but then has a l开发者_如何学运维ink to an XHTML namespace?


It looks like somebody was using an XHTML doctype, and the associated xmlns attribute:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

And then they heard HTML5 was the shiny new doctype, so they changed to that and ended up with:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" >

Just to make it clear, this is what it should be:

<!DOCTYPE html>
<html>


Your code provided,

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

is perfectly fine. It means that the web page is using XHTML5, an XML serialization of HTML5. If you would like your pages to be rendered as proper XHTML5, though, the content-type header of the page should be sent as application/xhtml+xml; text/html is not allowed in XHTML5.

For practical reasons (especially compatibility with previous IE versions, most notably IE 6), you should use HTML5, not XHTML5, like the following:

<!DOCTYPE html>
<html>

Note, of course, that the xmlns attribute has been removed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜