<ol>

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.).

In general, ordered list items have a preceding marker, such as a letter or number. (通常,有序列表项具有前置标记,例如字母或数字。)

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 you do not specify any additional attribute, then the content of the <ol> tag is by default numbered with Arabic numbers, starting with one.

Both the <ol> and <ul> tags represent a list of items. However, there is a difference with the <ol> tag where the order is meaningful.

Normally, the <ol> and <ul> tags can nest as deeply as required, alternating between them as you want.

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

Syntax

Syntax (语法)

The <ol> tag comes in pairs. The content is written between the opening (<ol>) and closing (</ol>) tags.

Example of the HTML <ol> tag:

<!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>

In the given example, we used the start attribute with the value “50”. (在给定的示例中,我们使用了值为“50”的start属性。)

To determine the type of numbering elements instead of the type attribute, use the CSS list-style-type property. (要确定编号元素的类型而不是类型属性,请使用CSS list-style-type属性。)

Example of the HTML <ol> tag used with the CSS list-style-type property:

<!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

Attributes (属性)

AttributeValueDescription
compactcompactReduces indents and spacing between lines.
Not supported in HTML5. Instead, we recommend to use the CSS line-height property.
reversedreversedIndicates, that the list elements should be in the descending order (instead of the usual ascending order).
startnumberSets the number from which the ordered list begins. 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” …).
type1 AaIiDefines 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 signalled 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:

CSS text-shadow property adds shadow to text. CSS text-align-last property sets the alignment of the last line of the text. CSS line-height property specifies the height of a line. CSS letter-spacing property defines the spaces between letters/characters in a text. CSS word-spacing property sets the spacing between words.



请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部