W3C validator complains about duplicate div

I use div clear in several places in one HTML file, a la:

 #clear { clear: both; } 

using:

 <div id="clear"> </div> 

But the W3C HTML5 validator seems to complain that each subsequent use after the initial use is a “duplicate identifier”:

le validation errors

Why is this not so? How should you use clear divs several times on the same page if this is not technically sound?

Note. This is basically just an informative question, my HTML code is great for all modern browsers, and given that this is the only error the HTML5 validator can find, I'm not worried, but I just wanted to know why this is considered a problem.

+4
source share
4 answers

In HTML, id attributes must be unique within the entire document. If you want some transparent <div> elements, use class :

 .clear { clear: both; } 

 <div class="clear"> </div> 
+10
source

Because "Duplicate ID clear".

You cannot have more than one item with a specific identifier on a website. Use a class instead.

 .clear { /*code here*/ } <div class="clear"></div> 

Classes can be repeated as many times as you want, but identifiers can only be used once.

+2
source

id uniquely identifies an element and cannot be reused in a single document.

If you want to indicate that several elements have something in common, use a class. You will need to change your CSS to use the class selector .


However, adding extra elements that do nothing but a set of crisp ones is ugly, and you should probably look at an alternative method. I would suggest overflow: hidden in most cases.

+1
source

You must use the class attribute.

ID attribute values ​​must be unique on the page .

 <div class="clear"> </div> .clear { clear: both; } 
+1
source

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


All Articles