<ol>: The Ordered List element - HTML: HyperText Markup Language 编辑

The HTML <ol> element represents an ordered list of items — typically rendered as a numbered list.

Content categoriesFlow content, and if the <ol> element's children include at least one <li> element, palpable content.
Permitted contentZero or more <li>, <script> and <template> elements.
Tag omissionNone, both the starting and ending tag are mandatory.
Permitted parentsAny element that accepts flow content.
Implicit ARIA rolelist
Permitted ARIA rolesdirectory, group, listbox, menu, menubar, none, presentation, radiogroup, tablist, toolbar, tree
DOM interfaceHTMLOListElement

Attributes

This element also accepts the global attributes.

reversed
This Boolean attribute specifies that the list’s items are in reverse order. Items will be numbered from high to low.
start
An integer to start counting from for the list items. Always an Arabic numeral (1, 2, 3, etc.), even when the numbering type is letters or Roman numerals. For example, to start numbering elements from the letter "d" or the Roman numeral "iv," use start="4".
type
Sets the numbering type:
  • a for lowercase letters
  • A for uppercase letters
  • i for lowercase Roman numerals
  • I for uppercase Roman numerals
  • 1 for numbers (default)

The specified type is used for the entire list unless a different type attribute is used on an enclosed <li> element.

Note: Unless the type of the list number matters (like legal or technical documents where items are referenced by their number/letter), use the CSS list-style-type property instead.

Usage notes

Typically, ordered list items display with a preceding marker, such as a number or letter.

The <ol> and <ul> elements may nest as deeply as desired, alternating between <ol> and <ul> however you like.

The <ol> and <ul> elements both represent a list of items. The difference is with the <ol> element, the order is meaningful. For example:

  • Steps in a recipe
  • Turn-by-turn directions
  • The list of ingredients in decreasing proportion on nutrition information labels

To determine which list to use, try changing the order of the list items; if the meaning changes, use the <ol> element — otherwise you can use <ul>.

Examples

Simple example

<ol>
  <li>Fee</li>
  <li>Fi</li>
  <li>Fo</li>
  <li>Fum</li>
</ol>

The above HTML will output:

Using Roman Numeral type

<ol type="i">
  <li>Introduction</li>
  <li>List of Greivances</li>
  <li>Conclusion</li>
</ol> 

The above HTML will output:

Using the start attribute

<p>Finishing places of contestants not in the winners’ circle:</p>

<ol start="4">
  <li>Speedwalk Stu</li>
  <li>Saunterin’ Sam</li>
  <li>Slowpoke Rodriguez</li>
</ol>

The above HTML will output:

Nesting lists

<ol>
  <li>first item</li>
  <li>second item  <!-- closing </li> tag not here! -->
    <ol>
      <li>second item first subitem</li>
      <li>second item second subitem</li>
      <li>second item third subitem</li>
    </ol>
  </li>            <!-- Here's the closing </li> tag -->
  <li>third item</li>
</ol>

The above HTML will output:

Unordered list inside ordered list

<ol>
  <li>first item</li>
  <li>second item  <!-- closing </li> tag not here! -->
    <ul>
      <li>second item first subitem</li>
      <li>second item second subitem</li>
      <li>second item third subitem</li>
    </ul>
  </li>            <!-- Here's the closing </li> tag -->
  <li>third item</li>
</ol>

The above HTML will output:

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of '<ol>' in that specification.
Living StandardNo change since last W3C snapshot, HTML5.
HTML5
The definition of 'HTMLOListElement' in that specification.
RecommendationAdded reversed and start attributed; un-deprecated type
HTML 4.01 Specification
The definition of '<ol>' in that specification.
RecommendationDeprecated compact and type.

Browser compatibility

BCD tables only load in the browser

See also

  • Other list-related HTML Elements: <ul>, <li>, <menu>
  • CSS properties that may be specially useful to style the <ol> element:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:94 次

字数:13099

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文