HTML <meter> data-* Attribute

A data-* attribute on a <meter> tag attaches additional data to the meter element.

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



A custom data-estimate attribute on a <meter> element.
The attribute value is not visible, but it is readable by JavaScript.

Calculating interest...

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


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

Uploading documents...


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

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

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

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

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:

8.0 Dec 2010
6.0 Aug 2011
13.0 Nov 2015
11.0 Dec 2010
6.0 Jul 2012

You may also like

 Back to <meter>

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

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