Jitendra Vyas Jitendra Vyas - 1 month ago 9
HTML Question

Is it not necessary to close the tag in HTML 5 like HTML?

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?

Answer

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.