Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 648975 of <ol>

  • Revision slug: Web/HTML/Element/ol
  • Revision title: <ol>
  • Revision id: 648975
  • Created:
  • Creator: shin
  • Is current revision? No
  • Comment

Revision Content

Summary

The HTML <ol> Element (or HTML Ordered List Element) represents an ordered list of items. Typically, ordered-list items are displayed with a preceding numbering, which can be of any form, like numerals, letters or Romans numerals or even simple bullets. This numbered style is not defined in the HTML description of the page, but in its associated CSS, using the {{cssxref("list-style-type")}} property.

There is no limitation to the depth and imbrication of lists defined with the {{HTMLElement("ol")}} and {{HTMLElement("ul")}} elements.

Usage note: The {{HTMLElement("ol")}} and {{HTMLElement("ul")}} both represent a list of items. They differ in the way that, with the {{HTMLElement("ol")}} element, the order is meaningful. As a rule of thumb to determine which one to use, try changing the order of the list items; if the meaning is changed, the {{HTMLElement("ol")}} element should be used, else the {{HTMLElement("ul")}} is adequate.
  • Content categoriesFlow content, and if the <ol> element's children include at least one {{HTMLElement("li")}} element, palpable content.
  • Permitted content Zero or more {{HTMLElement("li")}} elements
  • Tag omission {{no_tag_omission}}
  • Permitted parent elements Any element that accepts flow content.
  • DOM interface {{domxref("HTMLOListElement")}}

Attributes

This element includes the global attributes.

{{htmlattrdef("compact")}} {{Deprecated_inline}}
This Boolean attribute hints that the list should be rendered in a compact style. The interpretation of this attribute depends on the user agent and it doesn't work in all browsers. {{noteStart}}Do not use this attribute, as it has been deprecated: the {{HTMLElement("ol")}} element should be styled using CSS. To give a similar effect than the compact attribute, the CSS property {{cssxref("line-height")}} can be used with a value of 80%.{{noteEnd}}
{{htmlattrdef("reversed")}} {{HTMLVersionInline(5)}}
This Boolean attribute specifies that the items of the item are specified in the reverse order, i.e. that the least important one is listed first.
{{htmlattrdef("start")}}{{HTMLVersionInline(5)}}
This integer attribute specifies the start value for numbering the individual list items. Although the ordering type of list elements might be Roman numerals, such as XXXI, or letters, the value of start is always represented as a number. To start numbering elements from the letter "C", use <ol start="3">.
Note: This attribute was deprecated in HTML4, but reintroduced in HTML5.
{{htmlattrdef("type")}}
Indicates the numbering type:
  • 'a' indicates lowercase letters,
  • 'A' indicates uppercase letters,
  • 'i' indicates lowercase Roman numerals,
  • 'I' indicates uppercase Roman numerals,
  • and '1' indicates numbers (default).

The type set is used for the entire list unless a different {{htmlattrxref("type", "li")}} attribute is used within an enclosed {{HTMLElement("li")}} element.

Note: This attribute was deprecated in HTML4, but reintroduced in HTML5. Unless the value of the list number matters (e.g. in legal or technical documents where items are to be referenced by their number/letter), the CSS {{cssxref("list-style-type")}} property should be used instead.

Examples

Simple example

<ol>
  <li>first item</li>
  <li>second item</li>
  <li>third item</li>
</ol>

Above HTML will output:

  1. first item
  2. second item
  3. third item

Using the start attribute

<ol start="7">
  <li>first item</li>
  <li>second item</li>
  <li>third item</li>
</ol>

Above HTML will output:

  1. first item
  2. second item
  3. third item

Nesting lists

<ol>
  <li>first item</li>
  <li>second item      <!-- Look, the closing </li> tag is not placed here! -->
    <ol>
      <li>second item first subitem</li>
      <li>second item second subitem</li>
      <li>second item third subitem</li>
    </ol>
  </li>                <!-- Here is the closing </li> tag -->
  <li>third item</li>
</ol>

Above HTML will output:

  1. first item
  2. second item
    1. second item first subitem
    2. second item second subitem
    3. second item third subitem
  3. third item

Nested <ol> and <ul>

<ol>
  <li>first item</li>
  <li>second item      <!-- Look, the closing </li> tag is not placed here! -->
    <ul>
      <li>second item first subitem</li>
      <li>second item second subitem</li>
      <li>second item third subitem</li>
    </ul>
  </li>                <!-- Here is the closing </li> tag -->
  <li>third item</li>
</ol>

Above HTML will output:

  1. first item
  2. second item
    • second item first subitem
    • second item second subitem
    • second item third subitem
  3. third item

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', 'grouping-content.html#the-ol-element', '<ol>')}} {{Spec2('HTML WHATWG')}}  
{{SpecName('HTML5 W3C', "grouping-content.html#the-ol-element", "HTMLOListElement")}} {{Spec2('HTML5 W3C')}}  
{{SpecName('HTML4.01', 'struct/lists.html#h-10.2', '<ol>')}} {{Spec2('HTML4.01')}}  

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{CompatGeckoDesktop("1.0")}} 1.0 1.0 1.0
reversed attribute 18 {{CompatGeckoDesktop("18.0")}} {{CompatNo}} {{CompatNo}} 5.2
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatGeckoMobile("1.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
reversed attribute {{CompatVersionUnknown}} {{CompatGeckoMobile("18.0")}} {{CompatNo}} {{CompatNo}} {{CompatVersionUnknown}}

See also

  • Other list-related HTML Elements: {{HTMLElement("ul")}}, {{HTMLElement("li")}}, {{HTMLElement("menu")}} and the obsolete {{HTMLElement("dir")}};
  • CSS properties that may be specially useful to style the <ol> element:
    • the {{cssxref("list-style")}} property, useful to choose the way the ordinal is displayed,
    • CSS counters, useful to handle complex nested lists,
    • the {{cssxref("line-height")}} property, useful to simulate the deprecated {{htmlattrxref("compact", "ol")}} attribute,
    • the {{cssxref("margin")}} property, useful to control the indent of the list.
{{HTMLRef}}

Revision Source

<h2 id="Summary">Summary</h2>
<p>The <strong>HTML <code>&lt;ol&gt;</code> Element</strong> (or <em>HTML Ordered List Element</em>) represents an ordered list of items. Typically, ordered-list items are displayed with a preceding numbering, which can be of any form, like numerals, letters or Romans numerals or even simple bullets. This numbered style is not defined in the HTML description of the page, but in its associated CSS, using the {{cssxref("list-style-type")}} property.</p>
<p>There is no limitation to the depth and imbrication of lists defined with the {{HTMLElement("ol")}} and {{HTMLElement("ul")}} elements.</p>
<div class="note">
 <strong>Usage note: </strong> The {{HTMLElement("ol")}} and {{HTMLElement("ul")}} both represent a list of items. They differ in the way that, with the {{HTMLElement("ol")}} element, the order is meaningful. As a rule of thumb to determine which one to use, try changing the order of the list items; if the meaning is changed, the {{HTMLElement("ol")}} element should be used, else the {{HTMLElement("ul")}} is adequate.</div>
<ul class="htmlelt">
 <li><dfn><a href="/en-US/docs/HTML/Content_categories" title="HTML/Content_categories">Content categories</a></dfn><a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content_categories#Phrasing_content">Flow content</a>, and if the <code>&lt;ol&gt;</code> element's children include at least one {{HTMLElement("li")}} element, palpable content.</li>
 <li><dfn>Permitted content</dfn> Zero or more {{HTMLElement("li")}} elements</li>
 <li><dfn>Tag omission</dfn> {{no_tag_omission}}</li>
 <li><dfn>Permitted parent elements</dfn> Any element that accepts <a href="/en-US/docs/HTML/Content_categories#flow_content" title="HTML/Content categories#flow content">flow content</a>.</li>
 <li><dfn>DOM interface</dfn> {{domxref("HTMLOListElement")}}</li>
</ul>
<h2 id="Attributes">Attributes</h2>
<p><span style="line-height: 21px;">This element includes the </span><a href="https://developer.mozilla.org/en-US/docs/HTML/Global_attributes" style="line-height: 21px;" title="HTML/Global attributes">global attributes</a><span style="line-height: 21px;">.</span></p>
<dl>
 <dt>
  {{htmlattrdef("compact")}} {{Deprecated_inline}}</dt>
 <dd>
  This Boolean attribute hints that the list should be rendered in a compact style. The interpretation of this attribute depends on the user agent and it doesn't work in all browsers. {{noteStart}}Do not use this attribute, as it has been deprecated: the {{HTMLElement("ol")}} element should be styled using <a href="/en-US/docs/CSS" title="CSS">CSS</a>. To give a similar effect than the <code>compact</code> attribute, the <a href="/en-US/docs/CSS" title="CSS">CSS</a> property {{cssxref("line-height")}} can be used with a value of <code>80%</code>.{{noteEnd}}</dd>
 <dt>
  {{htmlattrdef("reversed")}} {{HTMLVersionInline(5)}}</dt>
 <dd>
  This Boolean attribute specifies that the items of the item are specified in the reverse order, i.e. that the least important one is listed first.</dd>
 <dt>
  {{htmlattrdef("start")}}{{HTMLVersionInline(5)}}</dt>
 <dd>
  This integer attribute specifies the start value for numbering the individual list items. Although the ordering type of list elements might be Roman numerals, such as XXXI, or letters, the value of start is always represented as a number. To start numbering elements from the letter "C", use <code>&lt;ol start="3"&gt;</code>.
  <div class="note">
   <strong>Note</strong>: This attribute was deprecated in HTML4, but reintroduced in HTML5.</div>
 </dd>
 <dt>
  {{htmlattrdef("type")}}</dt>
 <dd>
  Indicates the numbering type:
  <ul>
   <li><code>'a'</code> indicates lowercase letters,</li>
   <li><code>'A'</code> indicates uppercase letters,</li>
   <li><code>'i'</code> indicates lowercase Roman numerals,</li>
   <li><code>'I'</code> indicates uppercase Roman numerals,</li>
   <li>and <code>'1'</code> indicates numbers (default).</li>
  </ul>
  <p>The type set is used for the entire list unless a different {{htmlattrxref("type", "li")}} attribute is used within an enclosed {{HTMLElement("li")}} element.</p>
  <div class="note">
   <strong>Note: </strong>This attribute was deprecated in HTML4, but reintroduced in HTML5. Unless the value of the list number matters (e.g. in legal or technical documents where items are to be referenced by their number/letter), the CSS {{cssxref("list-style-type")}} property should be used instead.</div>
 </dd>
</dl>
<h2 id="Examples">Examples</h2>
<h3 id="Simple_example" name="Simple_example">Simple example</h3>
<pre class="brush: html">&lt;ol&gt;
  &lt;li&gt;first item&lt;/li&gt;
  &lt;li&gt;second item&lt;/li&gt;
  &lt;li&gt;third item&lt;/li&gt;
&lt;/ol&gt;
</pre>
<p>Above HTML will output:</p>
<ol>
 <li>first item</li>
 <li>second item</li>
 <li>third item</li>
</ol>
<h3 id="Using_the_start_attribute">Using the <span style="font-family: Courier New;"><code>start</code></span> attribute</h3>
<pre class="brush: html">&lt;ol start="7"&gt;
  &lt;li&gt;first item&lt;/li&gt;
  &lt;li&gt;second item&lt;/li&gt;
  &lt;li&gt;third item&lt;/li&gt;
&lt;/ol&gt;
</pre>
<p>Above HTML will output:</p>
<ol start="7">
 <li>first item</li>
 <li>second item</li>
 <li>third item</li>
</ol>
<h3 id="Nesting_lists">Nesting lists</h3>
<pre class="brush: html">&lt;ol&gt;
  &lt;li&gt;first item&lt;/li&gt;
  &lt;li&gt;second item      &lt;!-- Look, the closing &lt;/li&gt; tag is not placed here! --&gt;
    &lt;ol&gt;
      &lt;li&gt;second item first subitem&lt;/li&gt;
      &lt;li&gt;second item second subitem&lt;/li&gt;
      &lt;li&gt;second item third subitem&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;                &lt;!-- Here is the closing &lt;/li&gt; tag --&gt;
  &lt;li&gt;third item&lt;/li&gt;
&lt;/ol&gt;
</pre>
<p>Above HTML will output:</p>
<ol>
 <li>first item</li>
 <li>second item
  <ol>
   <li>second item first subitem</li>
   <li>second item second subitem</li>
   <li>second item third subitem</li>
  </ol>
 </li>
 <li>third item</li>
</ol>
<h3 id="Nested_&lt;ol>_and_&lt;ul>">Nested &lt;ol&gt; and &lt;ul&gt;</h3>
<pre class="brush: html">&lt;ol&gt;
  &lt;li&gt;first item&lt;/li&gt;
  &lt;li&gt;second item      &lt;!-- Look, the closing &lt;/li&gt; tag is not placed here! --&gt;
    &lt;ul&gt;
      &lt;li&gt;second item first subitem&lt;/li&gt;
      &lt;li&gt;second item second subitem&lt;/li&gt;
      &lt;li&gt;second item third subitem&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;                &lt;!-- Here is the closing &lt;/li&gt; tag --&gt;
  &lt;li&gt;third item&lt;/li&gt;
&lt;/ol&gt;
</pre>
<p>Above HTML will output:</p>
<ol>
 <li>first item</li>
 <li>second item
  <ul>
   <li style="list-style-type:square">second item first subitem</li>
   <li style="list-style-type:square">second item second subitem</li>
   <li style="list-style-type:square">second item third subitem</li>
  </ul>
 </li>
 <li>third item</li>
</ol>
<h2 id="Specifications" name="Specifications">Specifications</h2>
<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'grouping-content.html#the-ol-element', '&lt;ol&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', "grouping-content.html#the-ol-element", "HTMLOListElement")}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('HTML4.01', 'struct/lists.html#h-10.2', '&lt;ol&gt;')}}</td>
   <td>{{Spec2('HTML4.01')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Chrome</th>
    <th>Firefox (Gecko)</th>
    <th>Internet Explorer</th>
    <th>Opera</th>
    <th>Safari</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>1.0</td>
    <td>{{CompatGeckoDesktop("1.0")}}</td>
    <td>1.0</td>
    <td>1.0</td>
    <td>1.0</td>
   </tr>
   <tr>
    <td><code>reversed</code> attribute</td>
    <td>18</td>
    <td>{{CompatGeckoDesktop("18.0")}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
    <td>5.2</td>
   </tr>
  </tbody>
 </table>
</div>
<div id="compat-mobile">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Android</th>
    <th>Firefox Mobile (Gecko)</th>
    <th>IE Mobile</th>
    <th>Opera Mobile</th>
    <th>Safari Mobile</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{CompatVersionUnknown}}</td>
    <td>{{CompatGeckoMobile("1.0")}}</td>
    <td>{{CompatVersionUnknown}}</td>
    <td>{{CompatVersionUnknown}}</td>
    <td>{{CompatVersionUnknown}}</td>
   </tr>
   <tr>
    <td><code>reversed</code> attribute</td>
    <td>{{CompatVersionUnknown}}</td>
    <td>{{CompatGeckoMobile("18.0")}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatNo}}</td>
    <td>{{CompatVersionUnknown}}</td>
   </tr>
  </tbody>
 </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
 <li>Other list-related HTML Elements: {{HTMLElement("ul")}}, {{HTMLElement("li")}}, {{HTMLElement("menu")}} and the obsolete {{HTMLElement("dir")}};</li>
 <li>CSS properties that may be specially useful to style the <code>&lt;ol&gt;</code> element:
  <ul>
   <li>the {{cssxref("list-style")}} property, useful to choose the way the ordinal is displayed,</li>
   <li><a href="/en-US/docs/CSS_Counters" title="CSS_Counters">CSS counters</a>, useful to handle complex nested lists,</li>
   <li>the {{cssxref("line-height")}} property, useful to simulate the deprecated {{htmlattrxref("compact", "ol")}} attribute,</li>
   <li>the {{cssxref("margin")}} property, useful to control the indent of the list.</li>
  </ul>
 </li>
</ul>
<div>
 {{HTMLRef}}</div>
Revert to this revision