What is the meter tag?
I this article I am explaining the meter tag. The output of both (progress and meter) tags is the same as we will see but there is the difference that actually the meter tag is used to represent a scalar measurement within a known range. The value can be fractional.Examples
Disk uses, the relevance of a query result, the fraction of a voting population to have selected a specific candidate.
What is the difference between the progress tag and the meter tag? Progress bar is used to display the progress of a specific task. Or a progress element represents the completion progress of a task. Whereas the meter tag is used to represent guages. We can think that a progress tag represents dynamic data whereas a meter tag represents static data.
Note:
Syntax
The Meter tag is an inline element, the same as a header, progress and so on.
Attributes
<meter></meter>
Apart from the Global Attributes and Event Attributes, the meter tag have 6 more attributes as shown in the following table:
The following inequalities must hold, as applicable:
Note: if you do not specify min or max then the range will be between 0.0 to 1.0 and the value must be in that range.
HTML DOM Meter Object
In the DOM the meter element is defined by METER that represents for HTML 5.
var x = document.getElementById("[Give id of the meter tag here]");
var x = document.createElement("METER");
Example 1: This example will show you how can you use a meter element in HTML 5.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<b>Meter without value</b>
<meter></meter>
<br/><br/>
<b>Meter with value but without min and max attribute</b>
<meter value="0.8"></meter>
<br/><br/>
<b>Meter with value, min and max attribute</b>
<meter min="0" max="100" value="17"></meter>
<br/><br/>
<b>Meter (when "min <= value < low")</b>
<meter min="0" max="100" value="17" low="25" high="75"></meter>
<br/><br/>
<b>Meter (when "high < value <= max")</b>
<meter min="0" max="100" value="80" low="25" high="75"></meter>
<br/><br/>
<b>Meter (when "low <= value <= high")</b>
<meter min="0" max="100" value="50" low="25" high="75"></meter>
<br/><br/>
<b>Meter with optimum attribute</b>
<meter min="0" max="100" value="24" low="25" high="75" optimum="80"></meter>
<br/><br/>
<b>Meter with optimum attribute</b>
<meter min="0" max="100" value="80" low="25" high="75" optimum="20"></meter>
</body>
</html>
The output of example 1:
Styling meter element: we can define various types of styles for the meter element using a progress selector.Example 2: This example will explain how to increase the width and height of a meter element.
Example 2: This example will explain how to increase the width and height of a meter element.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<style>
meter {
width: 400px;
height: 25px;
}
</style>
</head>
<body>
<b>Meter without value</b>
<meter></meter>
<br/><br/>
<b>Meter with value but without min and max attribute</b>
<meter value="0.8"></meter>
<br/><br/>
<b>Meter with value, min and max attribute</b>
<meter min="0" max="100" value="17"></meter>
<br/><br/>
<b>Meter (when "min <= value < low")</b>
<meter min="0" max="100" value="17" low="25" high="75"></meter>
<br/><br/>
<b>Meter (when "high < value <= max")</b>
<meter min="0" max="100" value="80" low="25" high="75"></meter>
<br/><br/>
<b>Meter (when "low <= value <= high")</b>
<meter min="0" max="100" value="50" low="25" high="75"></meter>
<br/><br/>
<b>Meter with optimum attribute</b>
<meter min="0" max="100" value="24" low="25" high="75" optimum="80"></meter>
<br/><br/>
<b>Meter with optimum attribute</b>
<meter min="0" max="100" value="80" low="25" high="75" optimum="20"></meter>
</body>
</html>
Output of the Example 2:
More in styling:
1. WebKit/Blink Browser: According to webkit.org, we can have 5 different pseudo classes that are given in the following table.
Example 3: This example explains how to reset the appearance of a meter element. To reset the appearance we use -webkit-appearance:none;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<style>
meter {
width: 300px;
height: 25px;
-webkit-appearance: none; /* Reset appearance */
border: 1px solid #ccc;
border-radius: 5px;
}
</style>
</head>
<body>
<b>Meter without value</b>
<meter></meter>
<br/><br/>
<b>Meter with value but without min and max attribute</b>
<meter value="0.8"></meter>
<br/><br/>
<b>Meter with value, min and max attribute</b>
<meter min="0" max="100" value="17"></meter>
<br/><br/>
<b>Meter (when "min <= value < low")</b>
<meter min="0" max="100" value="17" low="25" high="75"></meter>
<br/><br/>
<b>Meter (when "high < value <= max")</b>
<meter min="0" max="100" value="80" low="25" high="75"></meter>
<br/><br/>
<b>Meter (when "low <= value <= high")</b>
<meter min="0" max="100" value="50" low="25" high="75"></meter>
<br/><br/>
<b>Meter with optimum attribute</b>
<meter min="0" max="100" value="24" low="25" high="75" optimum="80"></meter>
<br/><br/>
<b>Meter with optimum attribute</b>
<meter min="0" max="100" value="80" low="25" high="75" optimum="20"></meter>
</body>
</html>
Output of the Example 3:
Example 4: How to render the background container?
According to the preceding table I have described that we can render the container using the -webkit-meter-bar pseudo-class, so to apply the rendering I am using the following code:
meter::-webkit-meter-bar {
background: none;
background-color: whiteSmoke;
box-shadow: 0 5px 5px -5px #00F inset;
border: 1px solid #0ff;
border-radius: 5px;
}
Complete Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<style>
meter {
width: 300px;
height: 25px;
-webkit-appearance: none; /* Reset appearance */
border: 1px solid #F0f;
border-radius: 5px;
}
meter::-webkit-meter-bar {
background: none;
background-color: whiteSmoke;
box-shadow: 0 5px 5px -5px #00F inset;
border: 1px solid #0ff;
border-radius: 5px;
}
</style>
</head>
<body>
<b>Meter without value</b>
<meter></meter>
<br/><br/>
<b>Meter with value but without min and max attribute</b>
<meter value="0.8"></meter>
<br/><br/>
<b>Meter with value, min and max attribute</b>
<meter min="0" max="100" value="17"></meter>
<br/><br/>
<b>Meter (when "min <= value < low")</b>
<meter min="0" max="100" value="17" low="25" high="75"></meter>
<br/><br/>
<b>Meter (when "high < value <= max")</b>
<meter min="0" max="100" value="80" low="25" high="75"></meter>
<br/><br/>
<b>Meter (when "low <= value <= high")</b>
<meter min="0" max="100" value="50" low="25" high="75"></meter>
<br/><br/>
<b>Meter with optimum attribute</b>
<meter min="0" max="100" value="24" low="25" high="75" optimum="80"></meter>
<br/><br/>
<b>Meter with optimum attribute</b>
<meter min="0" max="100" value="80" low="25" high="75" optimum="20"></meter>
</body>
</html>
Output of the Example 4:
Example 5: This example explains how to render the value of the meter element, it means inside the container how to apply the rendering.
According to the table we can render the meter elements using the following pseudo classes:
-webkit-meter-optimum-value
-webkit-meter-suboptimum-value
-webkit-meter-even-less-good-value
Code: I am using the following code:
meter::-webkit-meter-optimum-value {
box-shadow: 0 5px 5px -5px #999 inset;
background-image: linear-gradient(
25deg,
#002900 5%,
#003D00 5%,
#005200 25%,
#007A00 25%,
#00A300 55%,
#00CC00 55%,
#33D633 95%,
#66E066 95%,
#99EB99 100%
);
background-size: 100% 100%;
}
meter::-webkit-meter-suboptimum-value {
box-shadow: 0 5px 5px -5px #999 inset;
background-image: linear-gradient(
25deg,
#333300 5%,
#666600 5%,
#999900 25%,
#CCCC00 25%,
#FFFF00 55%,
#FFFF33 55%,
#FFFFCC 95%,
#FF3300 95%,
#B22400 100%
);
background-size: 100% 100%;
}
meter::-webkit-meter-even-less-good-value {
box-shadow: 0 5px 5px -5px #999 inset;
background-image: linear-gradient(
25deg,
#000000 5%,
#330000 5%,
#660000 25%,
#990000 25%,
#CC0000 55%,
#FF0000 55%,
#FF3333 95%,
#FF6666 95%,
#FF9999 100%
);
background-size: 100% 100%;
}
Complete Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<style>
meter {
width: 300px;
height: 25px;
-webkit-appearance: none; /* Reset appearance */
border: 1px solid #F0f;
border-radius: 5px;
}
meter::-webkit-meter-bar {
background: none;
background-color: whiteSmoke;
box-shadow: 0 5px 5px -5px #00F inset;
border: 1px solid #0ff;
border-radius: 5px;
}
meter::-webkit-meter-optimum-value {
box-shadow: 0 5px 5px -5px #999 inset;
background-image: linear-gradient(
25deg,
#002900 5%,
#003D00 5%,
#005200 25%,
#007A00 25%,
#00A300 55%,
#00CC00 55%,
#33D633 95%,
#66E066 95%,
#99EB99 100%
);
background-size: 100% 100%;
}
meter::-webkit-meter-suboptimum-value {
box-shadow: 0 5px 5px -5px #999 inset;
background-image: linear-gradient(
25deg,
#333300 5%,
#666600 5%,
#999900 25%,
#CCCC00 25%,
#FFFF00 55%,
#FFFF33 55%,
#FFFFCC 95%,
#FF3300 95%,
#B22400 100%
);
background-size: 100% 100%;
}
meter::-webkit-meter-even-less-good-value {
box-shadow: 0 5px 5px -5px #999 inset;
background-image: linear-gradient(
25deg,
#000000 5%,
#330000 5%,
#660000 25%,
#990000 25%,
#CC0000 55%,
#FF0000 55%,
#FF3333 95%,
#FF6666 95%,
#FF9999 100%
);
background-size: 100% 100%;
}
</style>
</head>
<body>
<b>Meter without value</b>
<meter></meter>
<br/><br/>
<b>Meter with value but without min and max attribute</b>
<meter value="0.8"></meter>
<br/><br/>
<b>Meter with value, min and max attribute</b>
<meter min="0" max="100" value="17"></meter>
<br/><br/>
<b>Meter (when "min <= value < low")</b>
<meter min="0" max="100" value="17" low="25" high="75"></meter>
<br/><br/>
<b>Meter (when "high < value <= max")</b>
<meter min="0" max="100" value="80" low="25" high="75"></meter>
<br/><br/>
<b>Meter (when "low <= value <= high")</b>
<meter min="0" max="100" value="50" low="25" high="75"></meter>
<br/><br/>
<b>Meter with optimum attribute</b>
<meter min="0" max="100" value="24" low="25" high="75" optimum="80"></meter>
<br/><br/>
<b>Meter with optimum attribute</b>
<meter min="0" max="100" value="80" low="25" high="75" optimum="20"></meter>
</body>
</html>
Output of the Example 5:
2. FireFox Browser: For the FireFox browser use “-moz” instead of “-webkit” and everything else is the same.
3. Internet Explorer: In IE you can use all these properties directly, like appearance.
Thank you for reading ! I hope this tutorial will surely help!
#HTML #HTML5 #Metertag #tutorial #html