ol tag (XHTML 1.1)

ordered list

Topics

The ol tag is used for creating an Ordered List, which is a list with items in a particular order. Numbers or letters are usually used to indicate the order. You can create a simple ordered list like this:

<ol>
<li>John Doe</li>
<li>Jane Doe</li>
<li>...and all the others</li>
</ol>

The result will look something like this:

  1. John Doe
  2. Jane Doe
  3. ...and all the others

As you can see, we use the <li> tag. It simply tells the browser that the containing text is a list item. Everything within a set of <ol> tags should be list items.

The type attribute

The most interesting attribute of the ol tag, is the type attribute. It allows you to define which kind of bulletpoints you want. Click the type link, for a list of possible values. Here's an example where we use letters instead of the default numbers:

<ol type="A">
<li>John Doe</li>
<li>Jane Doe</li>
<li>...and all the others</li>
</ol>

The result looks like this:

  1. John Doe
  2. Jane Doe
  3. ...and all the others

Unfortunately, the type attribute has been deprecated. If you wish to create pages which validates, you should use the CSS alternative list-style-type instead:

<ol style="list-style-type: A;">
<li>John Doe</li>
<li>Jane Doe</li>
<li>...and all the others</li>
</ol>

In general, CSS offers you a lot of options for styling you list. You can play around with the following CSS properties:

The start attribute

The start attribute can be used to define where in the number/letter sequence you wish to start. This is practial in several situations, for instance when you wish to create a long list, which are divided into several pages or sections. Here is an example of how to use it:

<ol type="1" start="5">
<li>John Doe</li>
<li>Jane Doe</li>
<li>...and all the others</li>
</ol>
  1. John Doe
  2. Jane Doe
  3. ...and all the others

Unfortunately, the start attribute has been deprecated, and there are no real CSS alternative, at least not one that will work in all the major browsers. For now, you will have to workaround the issue in other ways, for instance by using JavaScript, or accept the validation error. The start attribute still works in pretty much any browser.

Attributes

Attribute Deprecated Required Description
class  space-separated list of classes 
compactX reduced interitem spacing 
dir  direction for weak/neutral text 
id  document-wide unique id 
lang  language code 
startX starting sequence number 
style  associated style info 
title  advisory title 
typeX numbering style 

Events

Event Description
onclicka pointer button was clicked 
ondblclicka pointer button was double clicked 
onkeydowna key was pressed down 
onkeypressa key was pressed and released 
onkeyupa key was released 
onmousedowna pointer button was pressed down 
onmousemovea pointer was moved within 
onmouseouta pointer was moved away 
onmouseovera pointer was moved onto 
onmouseupa pointer button was released 



© htmlpedia.net 2008 - 2012