Isn't there a need to close a tag in HTML 5 like HTML?

Isn't it necessary to close the tag in HTML 5, like HTML? or is it a bug in the W3C validator

Why is this code valid in the 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 really acted in HTML5. But is there any advantage to this behavior being correct in HTML5. HTML5 creators think stricter XHTML rules are not suitable for the Web?

+6
source share
3 answers

This markup is really valid. <p> should not be closed in HTML 4.01 or HTML5. I'm not sure where you got the idea that HTML5 requires everything to be private, as in XHTML.

HTML5 is just plain HTML with additional new features (hence, the version goes from 4.01 to 5). This in no way comes from XHTML. You can close all of your HTML5 tags so that it looks like well-formed XML, but specification is not required .

+9
source

HTML5 creators think stricter XHTML rules are not suitable for the Web?

To a large extent, yes.

Their opinion is that it simply simplifies the creation of a web page. HTML was incredibly successful because almost anyone can create a working web page without knowing almost no HTML code. This is a very small learning curve that you can start with when they are ready.

If you need to know a lot of pedantic rules just for starters, then many people will not worry, and HTML will not be so successful.

+7
source

Exiting the closing tag for the <p> element is excluded in most situations, although there are several where this is not the case. Exact rules at the World Wide Web Consortium :

A p The end tag element can be omitted if immediately after the p element follows address , article , aside , blockquote , dir, div , dl , fieldset , footer , form , h1 , h2 , h3 , h4 , h5 , h6 , header , hr , menu , nav , ol , p, pre , section , table or ul , or if there is no more content in the parent element and the parent element rather than the element a href = " " rel = "nofollow noreferrer"> a .

So, for example, the following is not allowed:

 <a href="http://example.com><p>This paragraph is unclosed</a> 

But this is true:

 <div class="news"><p>Something important happened!</div> 

HTML never required closing the <p> - it was always optional. You can close your HTML tags so that it looks like well-formed XHTML, but this is optional. XHTML is more rigorous than HTML.

0
source

Source: https://habr.com/ru/post/897034/


All Articles