<li></li> → Can this Item have class

<li></li> → Can this Item have class?

I mean this →

<li class="class1"></li> → Can this Item have class. I mean with web laws is that ok?

Yes you can add a class to a list item if you want to.
The question is: do you wan t to?
Generally list items should all look the same, so I would normally add a class to a parent element like the <ul> and target all items like: .MyList li {...}
You do see people putting the same class on every list item, this is just tedious, repetitive bloat.

One of the few edge cases where you want to add a class to a list item may be in a nav menu, to mark the current page.

1 Like

sir, In WordPress we just need to put the class to one li rest will be repeated with the PHP loop.

“Yay” for WP creating all the bloat for you. :grinning:


Sometimes there can be a difference depending on the doctype, but when in doubt the W3C is a good place to look.


In particular, look at the “ATTLIST” for its ELEMENT. You will see that “%coreattrs” are allowed. Those are at


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.