是不是有必要像HTML一样关闭HTML 5中的标签? [英] Is it not necessary to close the tag in HTML 5 like HTML?

查看:106
本文介绍了是不是有必要像HTML一样关闭HTML 5中的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有必要像HTML一样关闭HTML 5中的标签?或者它是W3C验证器中的一个错误



为什么这段代码在W3C验证器中有效

 <!DOCTYPE html> 
< html lang =en>
< head>
< meta charset =utf-8>
< title> title< / title>
< link rel =stylesheethref =style.css>
< script src =script.js>< / script>
< / head>
< body>
< p>一些文字
< / body>
< / html>

如果它在HTML5中真的有效,我会感到惊讶。但是,在HTML5中保持这种行为是否有效还有什么好处。 HTML5的创作者是否认为更严格的XHTML规则对Web没有好处?解析方案

这个标记确实是有效的。 < p> 标签不要在HTML 4.01或HTML5中不必关闭。我不确定你是否知道HTML5需要像XHTML那样关闭所有东西。



< HTML5只是普通的HTML,带有额外的新功能(因此版本从4.01跳到5)。它不以任何方式派生自XHTML。您可以关闭所有HTML5标记,使其看起来像格式良好的XML,但该规范不会要求您。


Is it not necessary to close the tag in HTML 5 like HTML? or it's a bug in W3C validator

Why this code is valid in W3C validator

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>title</title>
    <link rel="stylesheet" href="style.css">
    <script src="script.js"></script>
  </head>
  <body>
<p>Some Text
  </body>
</html>

I would be surprised if it's really valid in HTML5. But is there any benefit to keep this behavior valid in HTML5. Do HTML5 creators think that stricter rules of XHTML were not good for Web?

解决方案

That markup is indeed valid. <p> tags don't have to be closed in HTML 4.01 or HTML5. I'm not sure where you got the idea that HTML5 requires everything to be closed like in XHTML.

HTML5 is just regular HTML with extra new features (hence the version jump from 4.01 to 5). It does not in any way derive from XHTML. You can close all of your HTML5 tags so it looks like well-formed XML, but the spec doesn't require you to.

这篇关于是不是有必要像HTML一样关闭HTML 5中的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆