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 self-service freelancing marketplace for people like you.

HTML <meter> class Attribute

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

Classnames are defined in a stylesheet or in a local <style> element.

Classes, i.e. classnames, are used to style elements.

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

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

Multiple classnames are separated by a space.

JavaScript uses classes to access 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>
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 self-service freelancing marketplace for people like you.

Guides