Table of Contents
Set numbering type through type attribute
Use CSS to control numbering styles (more flexible)
Home Web Front-end H5 Tutorial How to create an ordered list in HTML5?

How to create an ordered list in HTML5?

Jul 30, 2025 am 05:23 AM
html5 ordered list

To create an ordered list in HTML5, use the

    and <li> tags, 1. Use
      to define the ordered list, and use <li> to represent each item internally. 2. You can specify the starting number through the start property, 3. Set the number type such as numerals, letters or Roman numerals through the type property. 4. It is recommended to use the list-style-type of CSS or a custom counter to achieve more flexible style control to separate structures and styles.

      How to create an ordered list in HTML5?

      Creating an ordered list in HTML5 is simple. You only need to use the <ol></ol> tag and then nest the <li> tag to represent each item. It will be numbered by default, but the numbering style can also be modified through CSS.

      How to create an ordered list in HTML5?

      Create basic ordered lists using <ol></ol> and <li>

      Ordered lists are defined using the <ol></ol> (abbreviation of ordered list) tag, and each list item is wrapped with <li> (list item). for example:

       <ol>
        <li>Step 1: Prepare the materials</li>
        <li>Step 2: Mix raw materials</li>
        <li>Step 3: Baking and forming</li>
      </ol>

      The list written in this way will be automatically added with a number and will be incremented from 1. This is the most basic and common usage.

      How to create an ordered list in HTML5?

      If you want the number to start with a specific number, you can add the start attribute:

       <ol start="5">
        <li>Step 5: Check the finished product</li>
        <li>Step 6: Package and shipment</li>
      </ol>

      This will start with 5.

      How to create an ordered list in HTML5?

      Set numbering type through type attribute

      By default, ordered lists use Arabic numerals (1, 2, 3...), but you can also change the numbering style via type attribute:

        <li> type="1" : number (default)<li> type="a" : lowercase English letters<li> type="A" : capital letters<li> type="i" : lowercase Roman numeral<li> type="I" : capital Roman numeral

      For example:

       <ol type="A">
        <li>Option A</li>
        <li>Option B</li>
        <li>Option C</li>
      </ol>

      The display effects are A, B, and C.

      It should be noted that type attribute is still valid in HTML5, but in some modern development practices, it is recommended to use CSS to control numbering styles because this can better separate structures and styles.

      Use CSS to control numbering styles (more flexible)

      Although HTML provides type attributes, if you need more complex numbering styles, such as bracketed numbers (1., 2., 3.), or custom prefixes, it is recommended to use list-style-type attribute of CSS.

      For example:

       <ol style="list-style-type: lower-roman;">
        <li>Item 1</li>
        <li>Item 2</li>
        <li>Item 3</li>
      </ol>

      This can be displayed as i, ii, iii.

      You can also implement more advanced styles in combination with custom CSS counters, such as:

       ol {
        counter-reset: my-counter;
        list-style: none;
      }
      
      ol li::before {
        counter-increment: my-counter;
        content: ""th" counter(my-counter) "step:";
      }

      In this way, the formats such as "Step 1" and "Step 2" will be displayed before each list item.

      Basically that's it. Creating an ordered list is not complicated in itself, but you need to choose the appropriate method according to the scene, such as whether semantics are required, whether style customization is required, etc.

The above is the detailed content of How to create an ordered list in HTML5?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1596
276
What is the aside element for in HTML5? What is the aside element for in HTML5? Aug 12, 2025 pm 04:37 PM

Theelementshouldbeusedforcontenttangentiallyrelatedtothemaincontent,suchassidebars,pullquotes,definitions,advertisements,orrelatedlinks;2.Itcanbeplacedinsideoroutsideanarticledependingoncontext;3.ItisasemanticelementthatenhancesaccessibilityandSEObyp

How to create a simple HTML5 webpage How to create a simple HTML5 webpage Aug 12, 2025 am 11:51 AM

To create a simple HTML5 web page, you need to first use the declaration document type, and then build a basic structure containing, and, which sets the character encoding, viewport and title, add visible content such as title, paragraph, link, pictures and lists. Save it as a .html file and open it directly in the browser for viewing, without server support. This is the basis of a complete and effective HTML5 page.

What is the draggable attribute in HTML5 What is the draggable attribute in HTML5 Aug 12, 2025 am 09:50 AM

ThedraggableattributeinHTML5specifieswhetheranelementcanbedragged,withvalues"true","false",oranemptystring(sameas"true").2.Settingdraggable="true"enablesdrag-and-dropforanyelement,butJavaScripteventlistenerslik

How to create a custom checkbox with HTML5 How to create a custom checkbox with HTML5 Aug 16, 2025 am 07:05 AM

To create a custom checkbox, you must first use an HTML structure with label to ensure accessibility; 2. Hide the default checkbox through CSS but retain its functionality; 3. Use pseudo-elements and pseudo-classes to draw the selected state on the custom .checkmark elements; 4. Add hover, focus and select styles to enhance interactive feedback; 5. Keep native inputs present to support keyboard navigation and screen readers, and ultimately achieve beautiful and accessible custom checkboxes.

How do you use the autofocus attribute in HTML5? How do you use the autofocus attribute in HTML5? Aug 14, 2025 pm 06:47 PM

Theautofocusattributeautomaticallyfocusesaformelementwhenapageloads.2.Itisabooleanattribute,sonovalueisneeded—justincludeautofocusinthetag.3.Onlyoneelementperpageshoulduseittoavoidunpredictablebehavior.4.Itworksoninput,textarea,select,andbuttonelemen

How to use the nav tag for navigation links in HTML5 How to use the nav tag for navigation links in HTML5 Aug 15, 2025 am 05:55 AM

ThetaginHTML5isusedtodefineasectionofmajornavigationlinks,providingsemanticstructureandimprovingaccessibilityandSEO;itshouldwrapprimarynavigationelementslikemenusortablesofcontents,noteverylinkonapage,andcanbeenhancedwithARIAlabelssuchasaria-label=&q

What is a definition list in HTML5? What is a definition list in HTML5? Aug 20, 2025 pm 02:01 PM

AdefinitionlistinHTML5iscreatedusingtheelementtogroupterms()withtheirdefinitions(),allowingmultipletermstoshareadefinitionoratermtohavemultipledefinitions,makingitidealforFAQs,glossaries,metadata,andcontactdetailswhileimprovingaccessibilityandSEOthro

How to defer non-critical CSS in an HTML5 page? How to defer non-critical CSS in an HTML5 page? Aug 12, 2025 am 12:15 AM

To effectively improve page loading performance, you need to inline the critical CSS first and load the non-critical CSS asynchronously; 1. Use tools or manually identify the critical CSS and inline it to; 2. Use rel="preload" to combine onload, JavaScript dynamic loading or requestIdleCallback asynchronously; 3. Use media attributes to delay loading of conditional styles such as print or topics; 4. Merge and compress non-critical CSS to reduce requests; you can use the media="print" technique to achieve JavaScript-free asynchronous loading, thereby significantly optimizing the first-screen rendering speed.

See all articles