A headline value against a limit, drawn as an arc with its thresholds
marked around the outside.
How it works
Still a <meter>, with the same attributes as above, so
without CSS it falls back to a bar. Typed attr() reads the
value, limit and thresholds straight from the markup, so no additional
custom properties needed. This CSS treats a missing threshold as
max, so a bare meter is all green; min is taken to
be 0.
<label class="gauge">CPU
<meter value="59" max="100" low="70" high="90" optimum="0"></meter>
<span>59%</span>
</label>
.gauge meter {
--v: clamp(0, attr(value number, 0), var(--max));
--max: attr(max number, 1);
--low: attr(low number, var(--max));
--high: attr(high number, var(--max));
}
The meter's own bar is hidden, instead CSS paints two 240°
conic-gradient() layers. The value layer is clipped to the
content-box, which padding and
border-radius: 50% shrink to a smaller circle. The threshold
layer fills the border-box underneath. One radial mask then
keeps only the thick inner ring and the thin outer one.
.gauge meter {
box-sizing: border-box;
padding: calc(var(--size) * .05);
border-radius: 50%;
background:
conic-gradient(from -120deg, var(--c) calc(var(--v) / var(--max) * 240deg), var(--track) 0 240deg, transparent 0) content-box,
conic-gradient(from -120deg, var(--ok) calc(var(--low) / var(--max) * 240deg), var(--warn) 0 calc(var(--high) / var(--max) * 240deg), var(--danger) 0 240deg, transparent 0) border-box;
mask: radial-gradient(closest-side, transparent 64%, #000 calc(64% + 1px) 86%, transparent calc(86% + 1px) 92%, #000 calc(92% + 1px));
}
.gauge meter::-webkit-meter-bar { visibility: hidden }
.gauge meter::-moz-meter-bar { visibility: hidden }
Chromium only exposes the meter's region through its pseudo-elements, which
can't colour the arc. So CSS is needed: sign(value - threshold)
is 1 above the threshold and 0 or -1 at or below it. That assumes lower is
better (a low optimum, as here), which matches the regions the
meter itself uses. This can be scaled to a percentage and floored at 0%,
which lets color-mix() toggle between two colours. Two nested
mixes give the three regions.
--c: color-mix(in srgb, var(--danger) max(0%, sign(var(--v) - var(--high)) * 100%),
color-mix(in srgb, var(--warn) max(0%, sign(var(--v) - var(--low)) * 100%), var(--ok)));
The arc's open bottom ends a quarter of the way up the box, so the row
holding it is only 85% as tall, leaving a little room under the arc. This
can be accounted for:
.gauge { grid-template-rows: auto calc(var(--size) * .85) }
Typed attr() outside content is new. Gauge rules
sit inside @supports (width: attr(x px)), so browsers without
it get the plain meter bar with the number under it.