Loaders
Liquid Fill
A glass vessel filling with liquid, its moving surface produced by two soft-cornered squares rotating against each other.
Original by Plinth · MIT
Report a problem or suggest an improvementInstall
npx shadcn@latest add https://plinthui.com/r/liquid-fill.json// No hooks or handlers, so this stays a server component. The level is a CSS
// custom property, so a consumer drives it with an inline style rather than
// re-rendering anything.
const css = `
.fill {
--level: 62%;
position: relative;
width: 132px;
aspect-ratio: 1;
border-radius: 50%;
overflow: hidden;
background: #100d1e;
box-shadow:
inset 0 0 0 2px rgba(255, 255, 255, 0.14),
0 14px 34px rgba(0, 0, 0, 0.5);
isolation: isolate;
}
/* The wave is a SQUARE with a soft border-radius, rotating. Where its rounded
edge crosses the fill line you see a crest; as it turns, the crest travels.
That is the whole illusion — no path, no canvas, no per-frame maths. A
border-radius near 42% is the sweet spot: at 50% it is a circle and the edge
is flat to the eye, at 0% the corners read as corners. */
.fill__wave {
position: absolute;
left: 50%;
/* Top of the square sits at the fill line; the body below it is the liquid. */
top: calc(100% - var(--level));
width: 210%;
aspect-ratio: 1;
border-radius: 42%;
transform-origin: 50% 50%;
animation: fill-turn 7s linear infinite;
}
.fill__wave--a {
background: linear-gradient(180deg, #ff3d81, #b45bff 60%, #5b8cff);
opacity: 0.95;
}
/* A second wave turning the other way at a different rate. Two crests moving
in opposite directions interfere, so the surface never looks like one object
spinning — which is exactly what a single wave looks like. */
.fill__wave--b {
background: linear-gradient(180deg, #4affd0, #22a7ff 70%, #5b8cff);
opacity: 0.55;
animation: fill-turn-rev 11s linear infinite;
}
@keyframes fill-turn {
from { transform: translate(-50%, 0) rotate(0deg); }
to { transform: translate(-50%, 0) rotate(360deg); }
}
@keyframes fill-turn-rev {
from { transform: translate(-50%, 0) rotate(360deg); }
to { transform: translate(-50%, 0) rotate(0deg); }
}
/* A specular arc so the sphere reads as glass holding liquid, not a flat disc
with a pattern in it. */
.fill__gloss {
position: absolute;
inset: 0;
background:
radial-gradient(40% 30% at 32% 20%, rgba(255, 255, 255, 0.5), transparent 70%),
radial-gradient(90% 70% at 50% 120%, rgba(0, 0, 0, 0.45), transparent 60%);
pointer-events: none;
}
.fill__value {
position: absolute;
inset: 0;
display: grid;
place-items: center;
font: 650 22px/1 system-ui, sans-serif;
color: #fff;
text-shadow: 0 1px 10px rgba(0, 0, 0, 0.65);
}
@media (prefers-reduced-motion: reduce) {
.fill__wave { animation: none; transform: translate(-50%, 0) rotate(8deg); }
.fill__wave--b { display: none; }
}
`;
export function LiquidFill({ value = 62 }: { value?: number }) {
return (
<>
<style>{css}</style>
<div
className="fill"
role="progressbar"
aria-valuenow={value}
aria-valuemin={0}
aria-valuemax={100}
aria-label="Uploading"
style={{ ['--level' as string]: `${value}%` }}
>
<div className="fill__wave fill__wave--a" />
<div className="fill__wave fill__wave--b" />
<div className="fill__gloss" />
<div className="fill__value">{value}%</div>
</div>
</>
);
}