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.
A class attribute styling a <meter> element.
<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>
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.
<meter class="classnames">
Value | Description |
---|---|
classnames | One or more space-separated class names. |
A class attribute styling a <meter> element.
Clicking the button toggles a classname that resizes the element.
<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>
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.
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 |
Back to <meter>