Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML <progress> id Attribute

An id on a <progress> tag assigns an identifier to the element.

The identifier must be unique across the page.

Example

#

An id attribute on a <progress> element.

Loading files...
50%
<div>Loading files... </div>
<progress id="load-progress" value="50" max="100"> 50% </progress>

Using id

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

The id allows JavaScript to easily access the <progress> element.

It is also used to point to a specific id selector in a style sheet.

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


Syntax

<progress 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 <progress> element with a unique id attribute. The element is loading from 0 to 100% repeatedly. Clicking the button displays the current progress value.

Loading files...
50%
<div>Loading files... </div>
<progress id="myprogress" max="100" value="50"> 50% </progress>

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

<script>

  setInterval( function(){
      let value = document.getElementById("myprogress").value;
      value = Math.min(value + .1, 100) % 100;
      document.getElementById("myprogress").value = value;
  }, 10 );


  let show = () => {
    let element = document.getElementById("myprogress");
    alert("Value = " + parseInt(element.value));
  }

</script>

Code explanation

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

JavaScript locates the <progress> using the id.

It then increases the value of the <progress> by 1 each 10 milliseconds.


Browser support

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

Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides