pixeltocode
pixeltocode

Reputation: 5308

Should the CSS property list-style be applied to <ul>/<ol> or <li>?

Most sites show the syntax as applying list-style to the <li> but I've seen some tutorial sites (like this one) that apply list-style to the <ul> or <ol>.

Which is the 'correct' way?

Upvotes: 42

Views: 21751

Answers (3)

Pointy
Pointy

Reputation: 413737

According to the W3C CSS2 reference, which can be found here,

Another solution would be to specify 'list-style' information only on the list type elements:

ol.alpha  { list-style-type: lower-alpha }
ul        { list-style-type: disc }

Inheritance will transfer the 'list-style' values from OL and UL elements to LI elements. This is the recommended way to specify list style information.

So you can do it at the overall list level if all of your elements are going to be the same, but you can instead do it at the list entry level if for example some entries would have different glyphs (like a square instead of a disc) to convey some meaning. You can also do both, with the list level style serving as a default to be overridden (but be careful about selector precedence!).

Upvotes: 47

Stuart Memo
Stuart Memo

Reputation: 1178

The spec recommends that you that you set it on <ul> and <ol> tags, and not on <li>.

See http://www.w3.org/TR/REC-CSS1/#list-style

Upvotes: 0

Tom
Tom

Reputation: 30698

As not having a list style is generally more common that having a list style, I personally apply it to both in a global reset at the top of my stylesheet.

Upvotes: 1

Related Questions