HTML <progress> data-* Attribute

The data-* attribute on a <progress> tag attaches additional data to the progress element. To create a custom attribute, replace the * with a lowercase string, such as data-id, data-status, or data-location.

Example

#

A custom data-for attribute on a <progress> bar.
The attribute value is not visible, but it is readable by JavaScript.

Loading files...
50%
<div>Loading files... </div>
<progress data-for="progress of file loading" value="50" max="100"> 50% </progress>

Using data-*

The data-* attribute adds custom information to a <progress> element.

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

An <progress> 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 progress.


Syntax

<progress data-*="value">

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


Values

#

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

More Examples

A custom data-total attribute on a <progress> element.
Clicking the button will display the total value.

Processing invoices...
50%
<div>Processing invoices... </div>
<progress id="myprogress" data-total="1702 records" value="50" max="100"> 50% </progress>

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

<script>
  let show = () => {
    let element = document.getElementById("myprogress");
    alert("Total = " + element.getAttribute('data-total'));
  }
</script>

Code explanation

The <progress> tag has a custom data-total attribute.

The data-total attribute describes the total of the <progress>.

Clicks are handled by the onclick event.

Onclick invokes a JavaScript function that extracts and displays the <progress> total.

Note: Notice how the progress purpose displays immediately without server call.


Browser support

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

Chrome
8.0 Dec 2010
Firefox
16.0 Oct 2012
IE/Edge
10.0 Sep 2012
Opera
11.0 Dec 2010
Safari
6.0 Jul 2012

You may also like

 Back to <progress>
Guides