HTML <progress> Element

Publish in HTML Tutorial el 25/05/2025 15:11

The <progress> element in HTML is used to represent the completion progress of a task. It provides a visual indication of how much of a task has been completed, typically displayed as a horizontal bar that fills up as the progress increases. This element is commonly used in web applications to show loading status, file uploads, or any process with measurable progress.


The <progress> element supports two main attributes:

  • value: Specifies how much of the task has been completed. Must be between 0 and max (or 1 if max is not specified).
  • max: Defines the total amount of work required for the task. If not specified, it defaults to 1.


Basic Syntax

To use the <progress> element, simply define the value and optionally the max attribute:

This will render a progress bar filled to 70% of its total width. Browsers that do not support the <progress> element will display the fallback text inside the tag (e.g., "70%").


Example 1: Simple Static Progress Bar

This example shows a basic progress bar that does not change over time.

Play Code


Example 2: Indeterminate Progress Bar

If you don't know the exact progress, you can omit the value attribute to create an indeterminate progress bar (often shown as a moving animation).

Play Code


Example 3: Dynamic Progress Bar with JavaScript

In this example, we use JavaScript to update the progress bar's value every second until it reaches 100%.

Play Code


Example 4: Manual Progress Update with Button

This example allows users to click a button to increase the progress by 10% each time.

Play Code


Example 5: Multiple Progress Bars with JavaScript Loop

This example dynamically creates 5 progress bars and updates them simultaneously using JavaScript.

Play Code


Tips & Tricks

  • Use the max attribute to scale your progress values accordingly (e.g., for file uploads, set max="100" for percentage-based progress).
  • Always provide fallback content inside the <progress> tag for browsers that don't support it.
  • You can style the <progress> element using CSS, but note that styling may vary across browsers due to default user agent styles.
  • Combine with JavaScript to make dynamic progress indicators for long-running tasks like AJAX requests or animations.
  • Avoid using the <progress> element for representing static data like statistics; use a custom bar chart instead.

También te puede interesar

HTML <style> Element
HTML <style> Element

The <style> HTML element contains style information for a document, or part of a document. ...

HTML <strong> Element
HTML <strong> Element

The <strong> element is used to indicate that its content has strong importance, seriousnes...

HTML <span> Element
HTML <span> Element

The <span> element is an inline container used to mark up a part of a text or document. Unl...

HTML <source> Element
HTML <source> Element

The <source> element is used to specify multiple media resources for media elements like &l...

HTML <small> Element
HTML <small> Element

The <small> element is used to represent side-comments and small print, typically for discl...

HTML <section> Element
HTML <section> Element

HTML <section> Element: The Complete Guide The <section> element is a semantic HTML ...