HTML <meter> class Attribute

The class attribute on a <meter> tag assigns one or more classnames to the meter element. Classes are used to style elements. Classnames are defined in a stylesheet or in a local <style> element.

Example

#

A class attribute styling a <meter> element.

Loading files...

75%
<style>
  meter.meter-size {width:180px;height:30px;}
  meter.meter-size::-webkit-meter-optimum-value { background: #3630a3; }
  meter.meter-size::-webkit-meter-bar { background: #dfe7ff; }
</style>

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

<br />
<meter class="meter-size" value="0.75">75%</meter>

Using class

The class attribute assigns one or more classnames to the <meter> tag.

Multiple classnames are separated by a space.

Classes (i.e. classnames) are used for styling the meter element.

JavaScript uses classes to access one or more elements by classname.

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


Syntax

<meter class="classnames">

Values

#

Value Description
classnames One or more space-separated class names.

More Examples

A class attribute styling a <meter> element.
Clicking the button toggles a classname that resizes the element.

Installing software...

45%
<style>
  .meter-lg {width:180px;height:30px;}
  .meter-lg::-webkit-meter-optimum-value { background: #2eb2b9; }
  .meter-lg::-webkit-meter-bar { background: #d9f4f5; }

  .meter-fat {width:180px;height:50px;}
</style>

<div>Installing software...</div>

<br />
<meter id="mymeter" class="meter-lg" value="0.45">45%</meter>

<br />
<button onclick="toggle();">Toggle class</button>

<script>
  let toggle = () => {
    let element = document.getElementById("mymeter");
    element.classList.toggle("meter-fat");
  }
</script>

Code explanation

Two CSS classes are defined in the <style> element.

The class attribute in <meter> assigns one classname.

Repeatedly clicking the button toggles the second class, resizing the <meter> width and height.


Browser support

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