HTML <ol> data-* Attribute

A data-* attribute on an <ol> tag attaches additional data to the ordered list.

To create a custom attribute, replace * with a lowercase string, such as data-id, data-status, or data-location.



A custom data-title attribute on an ordered list.
The attribute value is not visible, but it is readable by JavaScript.

  1. Amsterdam
  2. London
  3. Berlin
  4. Paris
<ol data-title="List of location">

Using data-*

The data-* attribute adds custom information to an <ol> element.

The * part is replaced with a lowercase string, such as data-id, data-cost, or data-location.

An <ol> element can have any number of data-* attributes, each with their own name.

Using data-* attributes reduces the need for requests to the server.

Note: The data-* attribute is not visible and does not change the appearance of the ol.


<ol data-*="value">

Note: The * can be any string, such as data-iddata-costdata-supplier,  etc.



Value Description
value A string value. Can be numeric, alphanumeric, JSON, etc.

More Examples

A custom data-content attribute on an <ol> element.
Clicking the button will display the content value.

  1. Amsterdam
  2. London
  3. Berlin
  4. Paris

<ol id="myol" data-content="List of cities">

<button onclick="show();">Show data</button>

  let show = () => {
    let element = document.getElementById("myol");
    alert("Content = " + element.getAttribute('data-content'));

Code explanation

The <ol> tag has a custom data-content attribute.

The data-content attribute stores the content of the ordered list.

Clicks are handled by the onclick event.

Onclick invokes a JavaScript function that extracts and displays the <ol> content.

Note: Notice how the title displays immediately without server call.

Browser support

Here is when data-* support started for each browser:

1.0 Sep 2008
1.0 Sep 2002
1.0 Aug 1995
1.0 Jan 2006
1.0 Jan 2003

You may also like

 Back to <ol>

Author: Jack Poorte
Published: Jun 20 2021
Last Reviewed: Sep 30 2023

What's your favorite/least favorite part of Dofactory?