Are CSS selectors without properties of any effect?

I have a maintenance job and there is a huge CSS file in which I found many things, such as:

.xxxx {} 

That is, a selector with absolutely nothing in it. I think that they are useless, but there are so many of them, and I begin to doubt myself. Am I right that they can be safely removed? Or are they really doing something, and I have to keep them?

+6
source share
1 answer

I would say that this is the worst project in history (or a stronger challenger for the title ...), but you can use .

See below:

 document.styleSheets[0].cssRules[0].style.setProperty('color', 'red'); 
 .randomClass {} 
 <div class="randomClass">No styling?</div> 

You can connect, process and even modify style sheets. Even if the selector is empty of styles, this can be changed using code.

Thus, it is probably very safe to delete, but if you want to be 100% sure, either leave it there or go through all possible code branches.

+3
source

All Articles