HTML meter
Created By: chatGPT
HTML provides a
<meter>
element that represents a scalar value within a known range. It’s commonly used to display a percentage or a measure of a resource usage. The primary attributes of the <meter>
element include min, max, and value.<meter min="0" max="100" value="50">50%</meter>
In this example, the meter indicates that 50% of a possible range from 0 to 100 is being used. The user can also specify optional attributes such as low, high, and optimum to define different thresholds for the meter value.
<meter min="0" max="100" low="30" high="70" optimum="50" value="50">50%</meter>
The
low
threshold is set to 30, meaning values below this point will indicate a lower state. The high
threshold is set to 70, indicating that values above this will represent a higher state, and optimum
at 50 suggests the ideal value.<meter min="0" max="100" low="30" high="70" optimum="50" value="20">20%</meter>
Here’s how the meter might look at the low value, indicating it’s below the acceptable range:
<meter min="0" max="100" low="30" high="70" optimum="50" value="20">20%</meter>
To add some styling to the
<meter>
element, using CSS is essential. You can customize the appearance by adjusting colors or sizes:meter {
width: 100%;
height: 20px;
background: #e0e0e0;
}
meter[value="20"] {
background: red;
}
meter[value="50"] {
background: yellow;
}
meter[value="80"] {
background: green;
}
The above CSS modifies the background color of the meter based on its value, providing visual feedback about the level represented. A red background indicates a level that is low, yellow suggests a moderate level, and green indicates a high level.
<style>
meter {
width: 100%;
height: 20px;
background: #e0e0e0;
}
meter[value="20"] {
background: red;
}
meter[value="50"] {
background: yellow;
}
meter[value="80"] {
background: green;
}
</style>
To implement this in a full HTML page, you can combine the meter examples and style definitions:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Meter Example</title>
<style>
meter {
width: 100%;
height: 20px;
background: #e0e0e0;
}
meter[value="20"] {
background: red;
}
meter[value="50"] {
background: yellow;
}
meter[value="80"] {
background: green;
}
</style>
</head>
<body>
<h1>Meter Example</h1>
<meter min="0" max="100" low="30" high="70" optimum="50" value="20">20%</meter>
<meter min="0" max="100" low="30" high="70" optimum="50" value="50">50%</meter>
<meter min="0" max="100" low="30" high="70" optimum="50" value="80">80%</meter>
</body>
</html>