Glass vial meter
A vertical potion-vial meter whose liquid fills a wide bulb first and then rises into a narrow neck, with meniscus and sheen drawn as gradients and a pulsing low-state — all CSS, no images.
Reach for it when building
- game health and resource meters
- remaining quota or budget displays
- reading or scroll progress with personality
- countdown-to-limit warnings
- playful dashboards
<div class="gvm-demo">
<div class="gvm-row">
<div class="gvm-unit">
<div class="gvm-vial" id="gvm-live" role="meter" aria-valuemin="0" aria-valuemax="100" aria-valuenow="68" aria-label="Mira's health">
<div class="gvm-neck"><div class="gvm-fill" style="height: 0%;"></div></div>
<div class="gvm-bulb"><div class="gvm-fill" style="height: 94.4%;"></div></div>
</div>
<p class="gvm-name">Mira</p>
<p class="gvm-read" id="gvm-live-read">68 / 100</p>
<p class="gvm-flag" id="gvm-live-flag"></p>
</div>
<div class="gvm-unit">
<div class="gvm-vial gvm-low" role="meter" aria-valuemin="0" aria-valuemax="100" aria-valuenow="18" aria-valuetext="18 of 100, low" aria-label="Tobin's health">
<div class="gvm-neck"><div class="gvm-fill" style="height: 0%;"></div></div>
<div class="gvm-bulb"><div class="gvm-fill" style="height: 25%;"></div></div>
</div>
<p class="gvm-name">Tobin</p>
<p class="gvm-read">18 / 100</p>
<p class="gvm-flag">Low</p>
</div>
<div class="gvm-unit">
<div class="gvm-vial" role="meter" aria-valuemin="0" aria-valuemax="100" aria-valuenow="90" aria-label="Wren's health">
<div class="gvm-neck"><div class="gvm-fill" style="height: 64.3%;"></div></div>
<div class="gvm-bulb"><div class="gvm-fill" style="height: 100%;"></div></div>
</div>
<p class="gvm-name">Wren</p>
<p class="gvm-read">90 / 100</p>
<p class="gvm-flag"></p>
</div>
</div>
<div class="gvm-control">
<label for="gvm-range">Mira's health</label>
<input id="gvm-range" type="range" min="0" max="100" step="1" value="68">
</div>
<p class="gvm-note">The bulb holds the first 72 points and the neck the last 28, so the liquid fills the bulb before it climbs. At 25 or below the vial glows and pulses.</p>
</div>Colors come from shared theme tokens — --surface, --ink, --border, --accent and friends — so this CSS carries no palette
of its own. Use Runnable file to copy the tokens along with it.
.gvm-demo { max-width: 26rem; }
.gvm-row { display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: flex-start; }
.gvm-unit { display: flex; flex-direction: column; align-items: center; }
/* The highlight has to be the light end of each theme and the liquid has to
darken downward in both, so the four material colors are set per theme. */
.gvm-vial {
--gvm-shine: var(--surface);
--gvm-liquid-top: color-mix(in srgb, var(--bad) 70%, var(--surface));
--gvm-liquid-body: color-mix(in srgb, var(--bad) 45%, var(--surface));
--gvm-liquid-base: color-mix(in srgb, var(--bad) 60%, var(--ink));
display: flex;
flex-direction: column;
align-items: center;
}
[data-theme="dark"] .gvm-vial {
--gvm-shine: var(--ink);
--gvm-liquid-top: color-mix(in srgb, var(--bad) 80%, var(--ink));
--gvm-liquid-body: color-mix(in srgb, var(--bad) 70%, var(--surface));
--gvm-liquid-base: color-mix(in srgb, var(--bad) 40%, var(--ground));
}
.gvm-neck,
.gvm-bulb {
position: relative;
overflow: hidden;
background: var(--surface-2);
border: 2px solid color-mix(in srgb, var(--dim) 70%, var(--ink));
box-shadow: inset 0 3px 6px color-mix(in srgb, var(--ink) 30%, transparent);
}
.gvm-neck {
width: 1.1rem;
height: 1.75rem;
border-radius: 0.3rem 0.3rem 0 0;
border-bottom: none;
}
.gvm-bulb {
width: 2.75rem;
height: 4.5rem;
border-radius: 1.3rem 1.3rem 1rem 1rem;
}
/* Liquid: light top, body, darkened base — one gradient sells the depth.
The bulb holds 72% of the scale; the neck holds the last 28%, so the
inline heights are (value / 72) and ((value - 72) / 28) respectively. */
.gvm-fill {
position: absolute;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(
180deg,
var(--gvm-liquid-top),
var(--gvm-liquid-body) 55%,
var(--gvm-liquid-base)
);
transition: height 0.3s ease;
}
/* Meniscus: a light line riding the liquid surface. */
.gvm-fill::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 3px;
border-radius: 999px;
background: color-mix(in srgb, var(--gvm-shine) 60%, transparent);
}
/* Glass sheen: a vertical highlight streak on the bulb only. */
.gvm-bulb::after {
content: '';
position: absolute;
left: 15%;
top: 10%;
bottom: 14%;
width: 18%;
border-radius: 999px;
background: linear-gradient(
180deg,
color-mix(in srgb, var(--gvm-shine) 55%, transparent),
color-mix(in srgb, var(--gvm-shine) 8%, transparent)
);
pointer-events: none;
}
/* The glow sits on the bulb, outside its clip; a shadow on the fill would be
cut off by overflow: hidden. */
.gvm-low .gvm-bulb {
box-shadow:
inset 0 3px 6px color-mix(in srgb, var(--ink) 30%, transparent),
0 0 12px color-mix(in srgb, var(--bad) 70%, transparent);
}
.gvm-low .gvm-fill { animation: gvm-pulse 1.6s ease-in-out infinite; }
@keyframes gvm-pulse {
0%, 100% { filter: brightness(1); }
50% { filter: brightness(1.18); }
}
@media (prefers-reduced-motion: reduce) {
.gvm-low .gvm-fill { animation: none; }
}
.gvm-name {
margin: 0.5rem 0 0;
font-size: 0.875rem;
line-height: 1.3;
color: var(--dim);
}
.gvm-read {
margin: 0;
font-size: 1rem;
color: var(--ink);
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
/* Always rendered, so a vial going low never shifts the row. */
.gvm-flag {
margin: 0;
min-height: 1.3em;
font-size: 0.875rem;
line-height: 1.3;
font-weight: 600;
color: var(--bad);
}
.gvm-control {
display: flex;
flex-direction: column;
gap: 0.25rem;
margin-top: 1.25rem;
max-width: 18rem;
}
.gvm-control label { font-size: 0.875rem; color: var(--dim); }
.gvm-control input {
width: 100%;
height: 1.75rem;
margin: 0;
accent-color: var(--bad);
}
.gvm-note { margin: 0.75rem 0 0; color: var(--dim); }const LOW_THRESHOLD = 25;
const BULB_SHARE = 72;
const range = document.getElementById('gvm-range');
const vial = document.getElementById('gvm-live');
const readout = document.getElementById('gvm-live-read');
const flag = document.getElementById('gvm-live-flag');
const neckFill = vial.querySelector('.gvm-neck .gvm-fill');
const bulbFill = vial.querySelector('.gvm-bulb .gvm-fill');
function render() {
const value = Number(range.value);
const isLow = value <= LOW_THRESHOLD;
const bulbPercent = Math.min(100, (value / BULB_SHARE) * 100);
const neckPercent = Math.max(0, ((value - BULB_SHARE) / (100 - BULB_SHARE)) * 100);
const spoken = value + ' of 100' + (isLow ? ', low' : '');
bulbFill.style.height = bulbPercent.toFixed(1) + '%';
neckFill.style.height = neckPercent.toFixed(1) + '%';
vial.classList.toggle('gvm-low', isLow);
vial.setAttribute('aria-valuenow', String(value));
vial.setAttribute('aria-valuetext', spoken);
range.setAttribute('aria-valuetext', spoken);
readout.textContent = value + ' / 100';
flag.textContent = isLow ? 'Low' : '';
}
range.addEventListener('input', render);
render();Paste this into an agent to rebuild the pattern from scratch.
Build a vertical meter shaped as a glass vial — a wide bulb below a narrow neck — instead of a plain bar, for values where a bit of personality is welcome: game health, mana, remaining quota or budget.
The geometry is two stacked containers, both `overflow: hidden` with a sunken background, a 2px glassy border, and an inset top shadow. The bulb is roughly 2.75rem wide by 4.5rem tall with large top radii and slightly smaller bottom radii; the neck is 1.1rem wide, sits on top, and has no bottom border so the two read as one vessel.
The fill math is the pattern's core: the bulb represents the first 72% of the scale and the neck the remaining 28%. For a value v (0–100), the bulb's fill height is `min(100, v / 72 * 100)` percent and the neck's is `max(0, (v - 72) / 28 * 100)` percent — liquid visibly fills the bulb first, then climbs the neck. Fills are bottom-anchored absolute divs with inline percentage heights and a height transition, so a changed value pours rather than jumps. At 0 both fills are empty and the meniscus is clipped away with them.
Three gradient tricks sell the material, all derived from tokens with color-mix, no images: the liquid is a three-stop vertical gradient (lightened top, body, darkened base); the meniscus is a 3px light line drawn as the fill's `::before` riding the liquid surface; the sheen is a vertical highlight streak on the bulb's `::after`, offset left, fading downward. Keep the highlight color and the three liquid stops in custom properties on the vial and set them per theme: the highlight mixes from the surface token on a light theme and from the ink token on a dark one, because a "white" streak built from a dark surface token turns into a dark smear, and the liquid must still run light to dark from top to base.
At or below 25%, add a low state: an outer glow in the danger color and a gentle brightness pulse on the liquid. Put the glow's box-shadow on the bulb, not on the fill — the bulb's `overflow: hidden` clips a shadow cast by the fill. Wrap the pulse in `prefers-reduced-motion` so it stops entirely for people who ask for less motion; the glow stays. Never let color and motion carry the low state alone: a "Low" flag appears in words under the readout, in a slot that is always reserved so the row does not shift when it shows.
Expose the value with `role="meter"`, `aria-valuenow/min/max`, an accessible name that says whose value it is, and an `aria-valuetext` that adds "low" when the low state is on. Print a short name and the numeric readout beneath in tabular figures at body size — the vial is the mood, the number is the truth.
When the value is user-adjustable, drive it from a labeled native range input rather than making the vial itself draggable; on input, recompute both fill heights, toggle the low state, and update the meter's ARIA values and the readout together. Mirror the same value text on the range so a screen reader hears "low" at the moment the glow appears.
Every color comes from theme custom properties, and the glass has to stay glassy in both light and dark themes.