HTML HTML Tutorial HTML Forms HTML Graphics HTML Media HTML APIs HTML Tags



HTML Tag: progress

The <progress> tag is used to represent the progress of a task or process. It is typically used in conjunction with JavaScript to update the progress bar as the task progresses.

Brief Explanation

The <progress> tag is a self-closing tag that can be used to display a progress bar on a web page. The tag has two required attributes: value and max. The value attribute specifies the current value of the progress bar, while the max attribute specifies the maximum value of the progress bar.

The <progress> tag can be used to display the progress of a file upload, a download, or any other task that takes a certain amount of time to complete. The progress bar can be updated using JavaScript, which allows for real-time updates as the task progresses.

Code Examples

Here are some examples of how the <progress> tag can be used:

Example 1: Basic Usage

The following code will display a progress bar with a value of 50 out of a maximum of 100:

  <progress value="50" max="100"></progress>

Example 2: Updating the Progress Bar

The following code will display a progress bar with a value of 0 out of a maximum of 100. When the user clicks the "Start" button, the progress bar will be updated every second until it reaches the maximum value:

  <progress id="myProgress" value="0" max="100"></progress>
  <button onclick="startProgress()">Start</button>

  <script>
    function startProgress() {
      var progress = document.getElementById("myProgress");
      var value = 0;
      var interval = setInterval(function() {
        value++;
        progress.value = value;
        if (value == progress.max) {
          clearInterval(interval);
        }
      }, 1000);
    }
  </script>

Example 3: Styling the Progress Bar

The following code will display a progress bar with a blue background and a yellow progress bar:

  <style>
    progress {
      background-color: blue;
    }
    progress::-webkit-progress-value {
      background-color: yellow;
    }
  </style>

  <progress value="50" max="100"></progress>

References

Activity