2

This is kinda stupid question but what markup should I use for ordered list which already has numbers? I'm currently using <OL> tag but It's kinda redundant in my eyes.

Markup:

<ol>
    <li>Chapter 1</li>
    <li>Chapter 2</li>
    <li>Chapter 3</li>
    <li>Chapter 4</li>
</ol>

Output:

1. Chapter 1
2. Chapter 2
3. Chapter 3
4. Chapter 4

For some reason I'm not using CSS so styling the <OL> is my last option.

kazinix
  • 28,987
  • 33
  • 107
  • 157
  • 1
    Why would you not use CSS? HTML is structure, CSS is styling. Also, possible duplicate: http://stackoverflow.com/questions/10877/how-can-you-customize-the-numbers-in-an-ordered-list – Charles Sprayberry Jan 28 '12 at 15:51
  • 1
    They are different. Styling the OL is not a problem actually but when I use Lynx Text Browser, CSS is does not matter. – kazinix Jan 28 '12 at 15:54
  • @CharlesSprayberry: I don't think they're duplicate questions. This one here is questioning the semantics of `
      ` if the content already contains numbering. The other one is purely about styling
    – Lukas Eder Jan 28 '12 at 15:55
  • 1
    @domanokz Good point. Different browsers will render differently. That's why it's important to use a doctype and the semantically correct OL when displaying an ordered list. You give the best chance of your content being rendered as you intended. – dubvfan87 Jan 28 '12 at 15:57
  • 1
    An `
      ` is an `
        `. There is absolutely no way the content could or should ever affect its semantic meaning. If it's an ordered list, it's an `
          `. *That's it.*
    – BoltClock Jan 28 '12 at 16:24
  • @LukasEder This **is** a styling issue. Semantically he's correct; it is an ordered list of chapters thus you use `
      `. The question boils down to the way the list elements are displayed in the browser. Sounds like styling to me.
    – Charles Sprayberry Jan 28 '12 at 16:24

5 Answers5

2

<ol> is your best option from a semantical point of view. According to the w3 specifications, you shouldn't use the type attribute anymore but use CSS styling instead:

http://www.w3.org/TR/html401/struct/lists.html#type-values

Having said this, <ol> + CSS is the "best" option. But using <ul> instead, might be the "most pragmatic" one, to avoid styling in your specific case.

UPDATE: Actually, the type attribute was "undeprecated" again in HTML5:

http://dev.w3.org/html5/markup/ol.html

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • I really want to upvote this answer for all the work that went into it. But changing the semantic meaning of an element based on its content feels wrong; however "pragmatic" it might be. Particularly with `type` attribute for supporting non-CSS browser I see no reason to put an ordered list into a `
      ` element.
    – Charles Sprayberry Jan 28 '12 at 16:31
  • @CharlesSprayberry: The OP has made a point in that they are targetting this for the Lynx text-browser. So I guess it's an "OK" workaround in a non-perfect world with real-life problems :-) – Lukas Eder Jan 28 '12 at 16:42
  • I'm not saying I don't understand the reasoning; I simply disagree with it. You're ultimately stating that the content can alter the semantics of an element if it can make the content *look* better. If we're opposed to changing semantics for styling in GUI browsers why should text browsers be any different? You're still changing semantics for styling. – Charles Sprayberry Jan 28 '12 at 18:25
  • Thanks for updating, I also think type attribute has nothing to do with the appearance. – kazinix Jan 29 '12 at 02:28
2

This isn't a semantics issue; this is a styling issue. Semantically what you're doing is correct. You have a list of elements that are in a specific order, thus you should use <ol>. The type of list bullet being displayed is a purely aesthetic styling choice and has nothing to do with semantics.

Perhaps the problem here really is the non-descriptive name of the chapters. Perhaps 'Chapter 1' would be better off 'Some Title Describing the Chapter'

Charles Sprayberry
  • 7,741
  • 3
  • 41
  • 50
1

In reality, <ol> means a list to be numbered by the browser; even the W3C HTML specifications use it this way, no matter what they might say in their prose. For details, check my treatise The difference between ul and ol elements in HTML. So if you don’t want browser-generated numbering, don’t use <ol>.

If you don’t want browser-generated bullets either, <ul> is not suitable either, though bullets would be less odd than generated numbers when the items have numbers in their content. In this case, <ul> might be suitable, but maybe not optimal.

This leaves you <div>, with class if needed. You can wrap each item inside <div> to make them start on a new line, and you can additionally wrap the entire list inside an outer <div> if this is needed for styling or scripting. Using just <br> between the items is another option, but then you have no convenient way of styling the items if you later wish to do that.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390
0

Are you using a 'css reset'? It might be resetting the default OL style.

Try addings this to your css:

ol { list-style-type: decimal; }

Structure your HTML like this:

<ol>
   <li>Chapter 1</li>
   <li>Chapter 2</li>
</ol>

Also make sure your doctype is correctly set. Prob. should use HTML5, but there are other options.

<!doctype html>

The difference between OL and UL is 'Ordered List' and 'Un-ordered List' use the right one when appropriate. If your list already contains a number you may just want to set list-style-type: none; in your css, but I would still use OL. It's more correct in this case I think.

dubvfan87
  • 641
  • 5
  • 18
0

You can resort to using the unordered list semantic markup <ul> instead; using this sample:

<ul>
    <li>Chapter 1</li>
    <li>Chapter 2</li>
    <li>Chapter 3</li>
    <li>Chapter 4</li>
</ul>

In the end; however, you should always use CSS for styling. It's unlikely you won't need to style your markup anyway, unless it's only for diagnostic purposes or providing basic information.

Technically, to be semantically correct you should keep your <ol> markup and use CSS to achieve the appearance you desire, but this may not be important depending on your situation and intentions.

Chris Hutchinson
  • 9,082
  • 3
  • 27
  • 33