HTML 5中是不是不需要像HTML那样关闭标签呢?
HTML 5中是不是不需要像HTML那样关闭标签呢?或者它是 W3C 验证器中的错误
为什么此代码在 W3C 验证器中有效
<!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>
如果它在 HTML5 中确实有效,我会感到惊讶。但是在 HTML5 中保持这种行为有效有什么好处吗? HTML5 创建者是否认为更严格的 XHTML 规则对 Web 不利?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该标记确实有效。
标签不必关闭在 HTML 4.01 或 HTML5 中。 我不确定您从哪里得到 HTML5 要求所有内容都像 XHTML 一样关闭的想法。
HTML5 只是带有额外新功能的常规 HTML(因此版本从 4.01 跃升至 5)。它绝不以任何方式派生自 XHTML。您可以关闭所有 HTML5 标记,使其看起来像格式良好的 XML,但规范并不要求您这样做。
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。这是一个非常小的入门学习曲线,人们可以在准备好后继续使用。
如果你需要了解很多迂腐的规则才能开始,那么很多人就不会费心,HTML 也不会那么成功。
Pretty much, yes.
Their view is that it just makes creating a web page harder. HTML has been wildly successful because just about anyone can create a working web page without knowing barely any HTML at all. It's a very small learning curve to get started which people can build upon when they're ready.
If you need to know a lot of pedantic rules just to get started, then many people won't bother, and HTML will not be as successful.
在大多数情况下,保留
元素的结束标记是有效的,但也有少数情况是无效的。 万维网联盟的具体规则是:
因此,例如,以下内容是无效的:
但这是有效的:
HTML 从来不需要关闭
标记 - 它始终是可选的。您可以关闭 HTML 标记,使其看起来像格式良好的 XHTML,但这不是必需的。 XHTML 比 HTML 更严格。
Leaving the closing tag for a
<p>
element out is valid in most situations, though there are a few where it isn't. The exact rules at the World Wide Web Consortium are:So, for example, the following is invalid:
But this is valid:
HTML never required the
<p>
tag to be closed—it was always optional. You may close your HTML tags so it looks like well-formed XHTML, but that isn't necessary. XHTML is more strict than HTML.