HTML <ol> Tag

HTML <ol> tag is used to create an ordered list, which contains elements in a certain sequence.

Each element of the ordered list starts with the opening <li> tag and ends with the closing tag </li>. In addition to the text, the <li> tag may include other HTML elements (lists, images, headings, paragraphs, etc.).

The following values can be used as numbering elements: Arabic numbers (1, 2, 3, ...); uppercase Latin letters (A, B, C, ...); lowercase latin letters (a, b, c, ...); Roman capital numbers (I, II, III, ...); Roman lowercase numbers (i, ii, iii, ...). The type attribute is used to indicate the type of the numbered list.

If do not specify any additional attributes, then the content of the <ol> tag is by default numbered with Arabic numbers, starting with one.

If the CSS properties are applied to the <ol> tag, then the elements nested in the <li> tag inherit them.

Syntax

The <li> tag comes in pairs; the closing tag is required.

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <ol>
      <li>Appetizers</li>
      <li>Hot</li>
      <li>Salads</li>
    </ol>
    <ol start="50">
      <li>Cold drinks</li>
      <li>Hot drinks</li>
      <li>Ice-Cream</li>
    </ol>
    <ol type="A">
      <li>Coca-Cola</li>
      <li>Ice Tea</li>
      <li>Fanta</li>
    </ol>
  </body>
</html>

Result

In the given example we used the start attribute with the value "50".

CSS properties

To determine the type of numbering elements instead of the type attribute, you can use the CSS list-style-type property.

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <h2>Examples of ordered lists</h2>
    <ol style="list-style-type: upper-roman">
      <li>Cold drinks</li>
      <li>Hot drinks</li>
      <li>Ice-Cream</li>
    </ol>
    <ol style="list-style-type: hebrew">
      <li>Coca-Cola</li>
      <li>Fanta</li>
      <li>Ice Tea</li>
    </ol>
    <ol style="list-style-type: decimal">
      <li>Coca-Cola</li>
      <li>Fanta</li>
      <li>Ice Tea</li>
    </ol>
  </body>
</html>

Result

Attributes

Attribute Value Description
compact compact Reduces indents and spacing between lines.
Not supported in HTML5. Instead, we recommend to use CSS property line-height.
reversed reversed Indicates, that list elements should go in descending order (instead of the usual ascending order).
start number Sets the number from which the ordered list will begin. The value must be an integer, negative values may be used. When used with letters (type = "A" and type = "a"), the number indicated in the attribute value corresponds to the ordinal number of the letter in the alphabet. For example, start = "5", will correspond to the letter "E" and the list will begin with it. If start = "27" is specified, the list becomes two-digit ("27" = "AA", "28" = "AB", "29" = "AC" ...).
type 1
A
a
I
i
Defines the type of the list marker.

The <ol> tag supports the Global Attributes and the Event Attributes.

How to style <ol> tag

Common properties to alter the visual weight/emphasis/size of text in <ol> tag:?

  • CSS font-style property sets the style of the font. normal | italic | oblique | initial | inherit
  • CSS font-family property specifies a prioritized list of one or more font family names and/or generic family names for the selected element.
  • CSS font-size property sets the size of the font.
  • CSS font-weight property defines whether the font should be bold or thick. CSS text-transform Property controls text case and capitalization.
  • CSS text-decoration property specifies the decoration added to text, and is a shorthand property for text-decoration-line, text-decoration-color, text-decoration-style

Coloring text in <ol> tag:

  • CSS color property describes the color of the text content and text decorations
  • CSS background-color property sets the background color of an element.

Text layout styles for <ol> tag:

  • CSS text-indent property specifies the indentation of the first line in a text block.
  • CSS text-overflow property specifies how overflowed content that is not displayed should be signaled to the user.
  • CSS white-space property specifies how white-space inside an element is handled.
  • CSS word-break property specifies where the lines should be broken.

Other properties worth looking at for <ol> tag


Browser support



Do you find this helpful?

Related articles