The HTML5 meter element

- 👤 Andrés Cruz

🇪🇸 En español

The HTML5 meter element

If you're learning HTML5 and want to completely master the <meter> element, this course takes you from the basics to advanced uses, including best practices, styles, accessibility, and real-world examples.

What the <meter> element is and what it's used for in HTML5

The <meter> element represents a value within a limited range. It is not an arbitrary bar or an indefinite progress indicator: it always requires a minimum value, a maximum value, and a current value.

It is used to express:

  • Levels (battery, storage, fuel)
  • Intensities or ranges (temperature, scores)
  • Measurable states within clear limits

Very useful for showing the progress of a task, I started using <meter> because it visually fit, but I soon discovered that it is not the best option for tasks that do not have a defined range. Below I explain why.

When to use <meter> and when NOT to use it

Use <meter> when:

  • the value is bounded
  • there is a clear and measurable range
  • you need to mark "low / normal / high" levels

Don't use it when:

  • the values are not predictable
  • there is no maximum
  • you need to show real task progress (that's where <progress> goes)

This perfectly matches what happened to me: when using <meter> for a task whose total was not defined, I noticed that the component was "lying," because it visually looked like progress, but semantically it wasn't.

Syntax of the <meter> element and a clear explanation of each attribute

The function of the meter tag is to indicate a measurement within a range; that is, it must be bounded, having a beginning and an end.

Its syntax is as follows:

<meter></meter> 

So far, nothing new; we see that like most tags in HTML, it presents an opening tag <meter> and a closing tag </meter>.

Attributes of the (tag) meter tag

  • value: A floating-point value that represents the current value of the measurement. This value must be between the maximum value (max) and the minimum value (min).
    • min <= value <= max.
  • min: Indicates the lower limit (lower bound) of the measurement range; and therefore the minimum possible value for the value attribute; this value must be smaller than the max attribute's value; if not specified, the minimum value will be zero.
  • max: Indicates the upper limit (upper bound) of the measurement range; and therefore the maximum possible value for the value attribute; this value must be larger than the min attribute's value; if not specified, the maximum value will be one.
  • low: Represents the upper limit of the low part of the measurement range. This must be greater than the min attribute, but less than high and max (if specified). If not specified, or if it is less than the minimum value, the low value is equal to the min value.
  • high: Represents the lower limit of the high part of the measurement range. This must be less than the max attribute, but greater than low and min (if specified). If not specified, or if it is greater than the maximum value, the high value is equal to the max value.
  • optimum: This attribute indicates the optimal or best value; which must be in the range defined by the low and min attributes. When the low and high attributes are used, they indicate the preferred zone for the given range. For example:

     

    • min <= optimum <= low; if the optimum value is in this range (between min and low) then the lower range is considered preferred.
    • high <= optimum <= max; if the optimum value is in this range (between high and max) then the upper range is considered preferred.

General rules for using the meter element

  • All the attributes mentioned above can be floating-point numbers.
  • According to the definitions of each attribute, the following expressions are true:
    • min <= value <= max.
    • min <= low <= high <= max (If low/high is specified).
    • min <= optimum <= max (If optimum is specified).

We must not use the (tag) meter tag for

  • Indicating the status of a progress or task; that's what the progress tag is for.
  • Representing values where the value is arbitrary or cannot be bounded.

Styles of the (tag) meter tag

Like other elements, we can define attributes like width, height, display, etc. to vary the size or behavior of the (tag) meter element; however, there are specific pseudo-classes for the meter element:

Pseudo-classesDescription
-webkit-meter-barDefines a color for the meter tag.
-webkit-meter-optimum-valueDefines a color for the meter tag when the meter is within the low-high range (low <= value <= high). The default color is green.
-webkit-meter-suboptimum-valueDefines a color for the meter tag when the meter is outside the low-high range (low > value or value > high). The default color is yellow.

Practical examples of using <meter> (real case and common uses)

Example 1

This example shows some of the attributes presented above: value, max and min.

In addition to this, we will use a script to vary the value of the meter tag over a determined time and appreciate its behavior over time.

Value: 1

To see the complete code for the experiment, click here.

Example 2

This example shows all the attributes presented above: value, max, min, low, and high; in addition, all of them present one of the pseudo-classes already defined and explained in the section above.

With the help of the previous script, we will see how:

  • Changing the meter color:

        #meter2::-webkit-meter-bar {
            background:blue;
        }


    Value: 1

  • Changing the meter color when the meter is in the range low <= optimum <= high:

        #meter2::-webkit-meter-bar {
            background:blue;
        }    


    Value: 1

  • Changing the color when it is out of this range; that is; low <= optimum <= high:

        #meter2::-webkit-meter-bar {
            background:blue;
        }  


    Value: 1

To see the complete code for the experiment, click here.

Example 3

We can also apply a gradient to it, instead of a solid color:

    #meter5 {
        width:60%;
        height:60px;
    }
    #meter5::-webkit-meter-bar {
        background: -webkit-gradient(linear, left top, left bottom, from(#FFF), to(#FFF), color-stop(0.20, #eee), color-stop(0.45, #eee), color-stop(0.55, #ccc));
        border-radius:5px;
    }
    #meter5::-webkit-meter-optimum-value {
        background: -webkit-gradient(linear, left top, left bottom, from(#FFF), to(#FFF), color-stop(0.20, #cea), color-stop(0.45, #7a3), color-stop(0.55, #7a3));
        border-radius:5px;
    }

    #meter5::-webkit-meter-suboptimum-value {
        background: -webkit-gradient(linear, left top, left bottom, from(#FFF), to(#FFF), color-stop(0.20, #ffc), color-stop(0.45, #db3), color-stop(0.55, #db3));
        border-radius:5px;
    }

Value: 1

To see the complete code for the experiment, click here.

Basic Example

<label>Level:</label> 
<meter value="50" min="0" max="100"></meter>

Example simulating task progress (based on my experience)

I once had to show how much a user had completed a task. Although I initially used <meter>, I ended up changing it to <progress>. Here I show you how it would have looked with <meter> if the range was known:

<label>Task Progress</label> 
<meter id="m1" value="30" min="0" max="100"></meter>

And to update it dynamically:

let m = document.getElementById("m1");
let v = 0;
setInterval(() => {
 if(v <= 100) {
   m.value = v;
   v++;
 }
}, 100);

Example with ranges and states

<label>Temperature Level</label> 
<meter value="65" min="0" max="100" low="30" high="70" optimum="60"></meter>

Customization and styles: how to change the design of the <meter>

WebKit-based browsers allow customization with pseudo-classes:

  • ::-webkit-meter-bar
  • ::-webkit-meter-optimum-value
  • ::-webkit-meter-suboptimum-value

I myself had to modify these styles when I wanted my meter to match the project's color palette.

Specific CSS Pseudo-classes

meter::-webkit-meter-optimum-value {
 background: green;
}
meter::-webkit-meter-suboptimum-value {
 background: yellow;
}
meter::-webkit-meter-even-less-good-value {
 background: red;
}

Advanced styles with gradients:

meter::-webkit-meter-bar {
 background: linear-gradient(to bottom, #fff, #ccc);
}

Accessibility of the <meter> element in HTML5

For a <meter> to be accessible:

  • Always use an associated label
  • Add alternative text if the meaning is not obvious
  • Consider using aria-valuenow, aria-valuemin, aria-valuemax when overly customizing the style

Common mistakes and best practices when using <meter>

  • ❌ Error: Using it for indefinite progress
    • (Exactly what happened to me the first time.)
  • ❌ Error: Not defining min and max
    • Causes the component to lose semantics.
  • ❌ Error: Values out of range
    • Some browsers ignore the meter.
  • ✔ Best practice: Show textual context
    • Example: "65% (high temperature)".

Frequently Asked Questions about the <meter> element

  • ❓ Can I use <meter> for task progress?
    • Only if you know the final value. If not, use <progress>.
  • ❓ Can I change the color of the <meter>?
    • Yes, but only with specific pseudo-classes in WebKit.
  • ❓ What happens if I don't define min or max?
    • The default values will be 0 and 1.

Conclusion

The <meter> element is powerful, semantic, and very useful when you need to show values within a range. Understanding its attributes and visual states not only improves accessibility but also allows you to build clearer interfaces. And as I found out when I tried to show task progress, correctly choosing between <meter> and <progress> makes the difference between a correct and a misleading interface.

I agree to receive announcements of interest about this Blog.

Learn to master the HTML5 element. Discover when to use it to display values ​​within a limited range (e.g., battery levels, temperatures) and why you should NOT use it for task progress. Complete guide with attributes, syntax, practical examples, CSS styles, and accessibility tips.

| 👤 Andrés Cruz

🇪🇸 En español