If you want to use something different from the default numbering of ordered lists, then all you have to do is choose a different style for your lists. CSS allows you to select from a wide variety of different list item shapes. For exampe, ordered list styles: decimal (default), lower-alpha, upper-alpha, lower-roman, upper-roman and none.

By default, most browsers display the ordered list numbers same font style as the body text. But what if I want change style only ordered list numbers. Here is a quick CSS tutorial on how you can use the ordered list <ol> and paragraph <p> element to design a stylish numbered list.

Overview

Basically, all what we need to do is style the <ol> element to Georgia font and set background image, and then reset the <p> element (nested in <ol>) to Arial. By default numbers of ordered list positioned outside of <ol> element. So if you want numbers lie on background, you need to set left margin to <li> element. I have to add left padding to <li> element in my example, to separate text from background image.

1. HTML source code

Make an ordered list. Don’t forget to wrap your text with a <p> tag.

<ol>
  <li>
    <p>This is first line</p>
  </li>
  <li>
    <p>Here is second line</p>
  </li>
  <li>
    <p>And last line</p>
  </li>
</ol>

Here is how the default ordered list will display:

step 1

2. ol element

Style the ol element:

ol {
  font: italic 1em Georgia, Times, serif;
  color: #999999;
}

The list will become like this:

step 2

3. ol p element

Now style the ol p element:

ol p {
  font: normal .8em Arial, Helvetica, sans-serif;
  color: #000000;
}

Your final list should look like this:

step 3

You can also add background under numbers. Don’t forget to reset margin for ol and ol p elements and add it to ol li element.

ol {
  background: #555555;
  margin:0px;
  padding: 0px;
}
p {
  margin:0px;
  padding:3px 0;
}
li {
  background: #ffffff;
  margin-left: 40px;
  padding-left: 10px;
}

This is how it look like now:

step 4

View my demo file to see more samples.

5 Responses to “Style Ordered List with CSS”

  1. ghezal ahmad says:

    Hi every one!
    I have some problem that how to design order list for persian language I mean from left to right for persain like الف ب ت ث
    plz help me

  2. Felicia says:

    Hi there
    Fabulous layouts above. Love them.
    One question you may be able to assist: why do your layouts work in IE6 and mine don’t? For IE I have to place a no-wrap otherwise the content will appear down the left side of the container only. I have tested the lists in IE but still having probs. Cheers

  3. Brian says:

    Hi,

    Is there a way to have an ol within another ol but is styled different? Example, I have an ol that is decimal and I’d like a second ol within that ol that is alpha:

    1. this is the first list
    A. this is the second list

    Please let me know if you can help.

    Thanks!

  4. Joost says:

    Cool thanks!

    I guess it’s a bit late, but…
    @Ghezal, put the attribute dir with the value rtl on it:

    With dir meaning “direction” and rtl meaning “right to left”

    @Brian you could use css inheritance if you are reluctant to add ids or classes
    ol {color: red}
    ol ol {color: black}
    Your decimals will be red and your alphabetic characters will be black.

  5. DB-Elements says:

    Great info. Thanks for posting!

Leave a Reply

Hello :)

You are blocking my beautiful
adverts with AdBlocker!
Disable it for CodEasily.com
if you want to see more articles
and leave comments here.

Thanks!