HTML <meter> data-* Attribute

The data-* attribute on a <meter> tag attaches additional data to the meter 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-estimate attribute on a <meter> element.
The attribute value is not visible, but it is readable by JavaScript.

Calculating interest...

20%
<div>Calculating interest...</div>

<br />
<meter value="0.2" data-estimate="May take 10 minutes...">20%</meter>

Using data-*

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

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

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


Syntax

<meter 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-size attribute on a <meter> tag.
Clicking the button will display the size value.

Uploading documents...

50%

<div>Uploading documents...</div>

<br />
<meter id="mymeter" value="0.5" data-size="3.87 TB">50%</meter>

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

<script>
  let show = () => {
    let element = document.getElementById("mymeter");
    alert("Size = " + element.getAttribute('data-size'));
  }
</script>

Code explanation

The <meter> tag has a custom data-size attribute.

The total files size of the <meter> is stored in the data-size.

Clicks are handled by the onclick event.

Onclick invokes a JavaScript function that extracts and displays the attribute value.

Note: Notice how the meter usage displays immediately without server call.


Browser support

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

Chrome
8.0 Dec 2010
Firefox
6.0 Aug 2011
IE/Edge
13.0 Nov 2015
Opera
11.0 Dec 2010
Safari
6.0 Jul 2012

You may also like

 Back to <meter>
Guides