Fill
import { useId, useRef, useState } from 'react';
const TABS = [
{ label: 'Water', body: 'Six glasses so far today. Two to go.' },
{ label: 'Coffee', body: 'One oat latte at 8:40. Easy does it.' },
{ label: 'Tea', body: 'A green tea after lunch, still warm.' },
];
const css = `
@keyframes tabs-fill-wave { to { transform: translateX(-12px); } }
.tabs-fill { width: 260px; }
.tabs-fill__list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tabs-fill__tab { position: relative; overflow: hidden; height: 40px; border: 0; border-radius: 10px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035); color: light-dark(#50535b, #c6c8cd); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; isolation: isolate; transition: color 0.25s 0.3s; }
.tabs-fill__liquid { position: absolute; left: -12px; right: -12px; bottom: -8px; z-index: -1; height: 0; background: light-dark(#373a40, #f1f2f3); transition: height 0.6s cubic-bezier(0.4, 0, 0.2, 1); }
.tabs-fill__liquid::before { content: ''; position: absolute; left: 0; right: 0; top: -5px; height: 6px; background: radial-gradient(circle at 6px 6px, light-dark(#373a40, #f1f2f3) 5.5px, transparent 6px) 0 0 / 12px 6px repeat-x; animation: tabs-fill-wave 0.7s linear infinite; }
.tabs-fill__tab[aria-selected='true'] { color: light-dark(#fbfcfd, #121417); transition-delay: 0.2s; }
.tabs-fill__tab[aria-selected='true'] .tabs-fill__liquid { height: calc(120% + 8px); }
.tabs-fill__tab:hover { box-shadow: inset 0 0 0 1px light-dark(#6d7179, #7d8087); }
.tabs-fill__tab:focus-visible { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 2px; }
.tabs-fill__panel { padding: 14px 4px 0; min-height: calc(3.1em + 14px); color: light-dark(#50535b, #c6c8cd); font-size: 13px; line-height: 1.55; }
@media (prefers-reduced-motion: reduce) {
.tabs-fill__liquid { transition: none; }
.tabs-fill__liquid::before { animation: none; }
}
`;
export function FillTabs() {
const id = useId();
const [sel, setSel] = useState(0);
const tabs = useRef<(HTMLButtonElement | null)[]>([]);
const onKeyDown = (e: React.KeyboardEvent) => {
const n = TABS.length;
const next = { ArrowRight: (sel + 1) % n, ArrowLeft: (sel + n - 1) % n, Home: 0, End: n - 1 }[e.key];
if (next === undefined) return;
e.preventDefault();
setSel(next);
tabs.current[next]?.focus();
};
return (
<>
<style>
{css}
</style>
<div className="tabs-fill">
<div className="tabs-fill__list" role="tablist" aria-label="Drinks" onKeyDown={onKeyDown}>
{TABS.map((t, i) => (
<button
key={t.label}
ref={(el) => {
tabs.current[i] = el;
}}
className="tabs-fill__tab"
type="button"
role="tab"
id={`${id}-tab-${i}`}
aria-selected={sel === i}
aria-controls={`${id}-panel-${i}`}
tabIndex={sel === i ? 0 : -1}
onClick={() => setSel(i)}
>
<span className="tabs-fill__liquid" aria-hidden="true" />
{t.label}
</button>
))}
</div>
{TABS.map((t, i) => (
<div key={t.label} className="tabs-fill__panel" role="tabpanel" id={`${id}-panel-${i}`} aria-labelledby={`${id}-tab-${i}`} hidden={sel !== i}>
{t.body}
</div>
))}
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initTabsFill(el) on the mounted element instead.
<div class="tabs-fill">
<div class="tabs-fill__list" role="tablist" aria-label="Drinks">
<button class="tabs-fill__tab" type="button" role="tab" id="tabs-fill-tab-0" aria-selected="true" aria-controls="tabs-fill-panel-0" tabindex="0"><span class="tabs-fill__liquid" aria-hidden="true"></span>Water</button>
<button class="tabs-fill__tab" type="button" role="tab" id="tabs-fill-tab-1" aria-selected="false" aria-controls="tabs-fill-panel-1" tabindex="-1"><span class="tabs-fill__liquid" aria-hidden="true"></span>Coffee</button>
<button class="tabs-fill__tab" type="button" role="tab" id="tabs-fill-tab-2" aria-selected="false" aria-controls="tabs-fill-panel-2" tabindex="-1"><span class="tabs-fill__liquid" aria-hidden="true"></span>Tea</button>
</div>
<div class="tabs-fill__panel" role="tabpanel" id="tabs-fill-panel-0" aria-labelledby="tabs-fill-tab-0">Six glasses so far today. Two to go.</div>
<div class="tabs-fill__panel" role="tabpanel" id="tabs-fill-panel-1" aria-labelledby="tabs-fill-tab-1" hidden="">One oat latte at 8:40. Easy does it.</div>
<div class="tabs-fill__panel" role="tabpanel" id="tabs-fill-panel-2" aria-labelledby="tabs-fill-tab-2" hidden="">A green tea after lunch, still warm.</div>
</div>@keyframes tabs-fill-wave { to { transform: translateX(-12px); } }
.tabs-fill { width: 260px; }
.tabs-fill__list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tabs-fill__tab { position: relative; overflow: hidden; height: 40px; border: 0; border-radius: 10px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035); color: light-dark(#50535b, #c6c8cd); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; isolation: isolate; transition: color 0.25s 0.3s; }
.tabs-fill__liquid { position: absolute; left: -12px; right: -12px; bottom: -8px; z-index: -1; height: 0; background: light-dark(#373a40, #f1f2f3); transition: height 0.6s cubic-bezier(0.4, 0, 0.2, 1); }
.tabs-fill__liquid::before { content: ''; position: absolute; left: 0; right: 0; top: -5px; height: 6px; background: radial-gradient(circle at 6px 6px, light-dark(#373a40, #f1f2f3) 5.5px, transparent 6px) 0 0 / 12px 6px repeat-x; animation: tabs-fill-wave 0.7s linear infinite; }
.tabs-fill__tab[aria-selected='true'] { color: light-dark(#fbfcfd, #121417); transition-delay: 0.2s; }
.tabs-fill__tab[aria-selected='true'] .tabs-fill__liquid { height: calc(120% + 8px); }
.tabs-fill__tab:hover { box-shadow: inset 0 0 0 1px light-dark(#6d7179, #7d8087); }
.tabs-fill__tab:focus-visible { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 2px; }
.tabs-fill__panel { padding: 14px 4px 0; min-height: calc(3.1em + 14px); color: light-dark(#50535b, #c6c8cd); font-size: 13px; line-height: 1.55; }
@media (prefers-reduced-motion: reduce) {
.tabs-fill__liquid { transition: none; }
.tabs-fill__liquid::before { animation: none; }
}function initTabsFill(root) {
var list = root.querySelector('[role="tablist"]');
var tabs = Array.prototype.slice.call(list.querySelectorAll('[role="tab"]'));
var panels = root.querySelectorAll('[role="tabpanel"]');
var sel = tabs.findIndex(function (tab) { return tab.getAttribute('aria-selected') === 'true'; });
function select(i) {
if (i === sel) return;
var prev = sel;
sel = i;
tabs.forEach(function (tab, k) {
tab.setAttribute('aria-selected', String(k === i));
tab.tabIndex = k === i ? 0 : -1;
});
panels.forEach(function (panel, k) { panel.hidden = k !== i; });
}
function onClick(e) {
var tab = e.target.closest('[role="tab"]');
if (tab) select(tabs.indexOf(tab));
}
function onKeyDown(e) {
var n = tabs.length;
var next = { ArrowRight: (sel + 1) % n, ArrowLeft: (sel + n - 1) % n, Home: 0, End: n - 1 }[e.key];
if (next === undefined) return;
e.preventDefault();
select(next);
tabs[next].focus();
}
list.addEventListener('click', onClick);
list.addEventListener('keydown', onKeyDown);
return function () {
list.removeEventListener('click', onClick);
list.removeEventListener('keydown', onKeyDown);
};
}
document.querySelectorAll('.tabs-fill').forEach(initTabsFill);Goal: Create a "Fill" tab set.
Visual behavior: Drink tabs that fill up like a glass: the chosen tab fills from the bottom with a moving wave on top, and the one you left drains.
Technique:
- The ARIA tabs pattern: a role="tablist" with an aria-label, buttons with role="tab", aria-selected and aria-controls, and role="tabpanel" panels labelled by their tab. Only the selected tab is in the Tab order (roving tabindex); the arrow keys, Home and End move between tabs and select as they go.
- Each tab has a liquid layer translated up when it is selected; a wavy surface on its ::before rolls sideways on a loop. The label colour changes after the liquid passes it.
Accessibility: Real ARIA tabs: arrow keys, Home and End move between tabs, only the selected tab is in the Tab order, and each panel is labelled by its tab. Decoration is aria-hidden. Under prefers-reduced-motion the tabs fill without rising or waving.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: neutral only. Black, white and grays, no hues. Use the color values above as written, or my project's closest neutral tokens.
Return a single self-contained component. No dependencies.Goal: Create a "Fill" tab set.
Visual behavior: Drink tabs that fill up like a glass: the chosen tab fills from the bottom with a moving wave on top, and the one you left drains.
Technique:
- The ARIA tabs pattern: a role="tablist" with an aria-label, buttons with role="tab", aria-selected and aria-controls, and role="tabpanel" panels labelled by their tab. Only the selected tab is in the Tab order (roving tabindex); the arrow keys, Home and End move between tabs and select as they go.
- Each tab has a liquid layer translated up when it is selected; a wavy surface on its ::before rolls sideways on a loop. The label colour changes after the liquid passes it.
Accessibility: Real ARIA tabs: arrow keys, Home and End move between tabs, only the selected tab is in the Tab order, and each panel is labelled by its tab. Decoration is aria-hidden. Under prefers-reduced-motion the tabs fill without rising or waving.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: use my project's existing color tokens. The color values above are grayscale placeholders. Map each one by its role (surface, text, border, accent, glow) to my theme, and keep their relative lightness so contrast and the effect still read.
Return a single self-contained component. No dependencies.Paste into Claude, ChatGPT or Cursor after filling in {{USER_STACK}}, {{USER_STYLING}} and {{USER_CONSTRAINTS}}. Neutral keeps the greys you see here; Match my project asks the model to map them onto your own colour tokens.
Free to use in any project, commercial included. MIT-0, no attribution required. Licence
About this component
Drink tabs that fill up like a glass: the chosen tab fills from the bottom with a moving wave on top, and the one you left drains.
- Dependencies
- None
- Difficulty
- Beginner
- Triggers
- click, state change, fill
- Techniques
- css transition, keyframes, radial gradient
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
Real ARIA tabs: arrow keys, Home and End move between tabs, only the selected tab is in the Tab order, and each panel is labelled by its tab. Decoration is aria-hidden. Under prefers-reduced-motion the tabs fill without rising or waving.