Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

xhtml

w3c

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?

like image 984
Jitendra Vyas Avatar asked Sep 10 '11 06:09

Jitendra Vyas


People also ask

Does html5 require closing tags?

Optional HTML Closing TagsSome closing tags are optional, however. The tags are optional because it's implied that a new tag would not be able to be started without closing it.

What happens if you don't close HTML tag?

If you don't add a closing tag the browser won't know where it ends. It will take the next tag and think it belongs to the previous tag without the closing tag.

Which HTML tags do not need to be closed?

There are some HTML elements which don't need to be closed, such as <img.../>, <hr /> and <br /> elements. These are known as void elements.


2 Answers

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.

like image 157
BoltClock Avatar answered Sep 28 '22 08:09

BoltClock


Do HTML5 creators think that stricter rules of XHTML were not good for Web?

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.

like image 36
Alohci Avatar answered Sep 28 '22 07:09

Alohci