HTML <meter> id Attribute

The id attribute on a <meter> tag assigns an identifier to the meter element. The identifier must be unique across the page.

Example

#

An id attribute on a <meter> element.

Loading files...

50%
<div>Loading files...</div>

<br />
<meter id="load-meter" value="0.5">50%</meter>

Using id

The id attribute assigns an identifier to the <meter> element.

The identifier must be unique across the page.

The id allows programmatic access to the <meter> element.

Tip:  id is a global attribute that can be applied to any HTML element.


Syntax

<meter id="identifier" />

Values

#

Value Description
identifier A unique alphanumeric string. The id value must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.).

More Examples

A <meter> element with a unique id.
Clicking the button displays the meter value.

Loading files...

35%

<div>Loading files...</div>

<br />
<meter id="mymeter" value="0.35">35%</meter>

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

<script>
  let show = () => {
    let element = document.getElementById("mymeter");
    alert("Value = " + element.value);
  }
</script>

Code explanation

The id attribute assigns a unique identifier for the <meter>.

Clicking the button calls JavaScript which locates the <meter> using the id.

Finally, the <meter> value is displayed in an alert box.


Browser support

Here is when id 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