Charge
const css = `
@keyframes toggle-charge-pulse { 50% { opacity: 0.45; } }
.toggle-charge { position: relative; display: inline-flex; align-items: center; gap: 12px; color: light-dark(#42454c, #e5e6e9); font-size: 14px; cursor: pointer; user-select: none; }
.toggle-charge__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.toggle-charge__track {
position: relative;
display: flex;
gap: 2px;
width: 58px;
height: 28px;
padding: 3px;
margin-right: 5px;
border-radius: 6px;
box-shadow: inset 0 0 0 2px light-dark(#6d7179, #7d8087);
}
.toggle-charge__track::after { content: ''; position: absolute; right: -5px; top: 9px; width: 3px; height: 10px; border-radius: 0 2px 2px 0; background: light-dark(#6d7179, #7d8087); }
.toggle-charge__input:focus-visible + .toggle-charge__track { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 4px; }
.toggle-charge__cell {
flex: 1;
margin: 1px 0;
border-radius: 2px;
background: light-dark(#ebedf0, #232529);
transition: background-color 0.15s ease calc((4 - var(--i)) * 0.05s);
}
.toggle-charge__bolt {
position: absolute;
left: 50%;
top: 50%;
width: 16px;
height: 16px;
margin: -8px 0 0 -8px;
fill: light-dark(#fbfcfd, #121417);
stroke: light-dark(#373a40, #f1f2f3);
stroke-width: 1.5;
stroke-linejoin: round;
opacity: 0;
transform: scale(0.4) rotate(-20deg);
transition: opacity 0.2s, transform 0.3s;
}
/* Cells fill left to right, then the bolt drops in and the last cell keeps charging. */
.toggle-charge__input:checked + .toggle-charge__track .toggle-charge__cell { background: light-dark(#42454c, #e5e6e9); transition-delay: calc(var(--i) * 0.09s); }
.toggle-charge__input:checked + .toggle-charge__track .toggle-charge__cell:last-of-type { animation: toggle-charge-pulse 1.2s ease-in-out 0.6s infinite; }
.toggle-charge__input:checked + .toggle-charge__track .toggle-charge__bolt { opacity: 1; transform: none; transition: opacity 0.2s 0.45s, transform 0.4s cubic-bezier(0.34, 1.8, 0.64, 1) 0.45s; }
@media (prefers-reduced-motion: reduce) {
.toggle-charge__track * { transition-duration: 0.01s !important; transition-delay: 0s !important; animation: none !important; }
}
`;
export function ChargeToggle() {
return (
<>
<style>
{css}
</style>
<label className="toggle-charge">
<input className="toggle-charge__input" type="checkbox" role="switch" />
<span className="toggle-charge__track" aria-hidden="true">
{[0, 1, 2, 3, 4].map((i) => (
<span key={i} className="toggle-charge__cell" style={{ '--i': i } as React.CSSProperties} />
))}
<svg className="toggle-charge__bolt" viewBox="0 0 24 24">
<path d="M13.5 2L5 13.5h6L10 22l9-12h-6.5z" />
</svg>
</span>
Fast charge
</label>
</>
);
}Markup where the component goes, CSS in your stylesheet. No JavaScript.
<label class="toggle-charge"><input class="toggle-charge__input" type="checkbox" role="switch"/><span class="toggle-charge__track" aria-hidden="true"><span class="toggle-charge__cell" style="--i:0"></span><span class="toggle-charge__cell" style="--i:1"></span><span class="toggle-charge__cell" style="--i:2"></span><span class="toggle-charge__cell" style="--i:3"></span><span class="toggle-charge__cell" style="--i:4"></span><svg class="toggle-charge__bolt" viewBox="0 0 24 24"><path d="M13.5 2L5 13.5h6L10 22l9-12h-6.5z"></path></svg></span>Fast charge</label>@keyframes toggle-charge-pulse { 50% { opacity: 0.45; } }
.toggle-charge { position: relative; display: inline-flex; align-items: center; gap: 12px; color: light-dark(#42454c, #e5e6e9); font-size: 14px; cursor: pointer; user-select: none; }
.toggle-charge__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.toggle-charge__track {
position: relative;
display: flex;
gap: 2px;
width: 58px;
height: 28px;
padding: 3px;
margin-right: 5px;
border-radius: 6px;
box-shadow: inset 0 0 0 2px light-dark(#6d7179, #7d8087);
}
.toggle-charge__track::after { content: ''; position: absolute; right: -5px; top: 9px; width: 3px; height: 10px; border-radius: 0 2px 2px 0; background: light-dark(#6d7179, #7d8087); }
.toggle-charge__input:focus-visible + .toggle-charge__track { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 4px; }
.toggle-charge__cell {
flex: 1;
margin: 1px 0;
border-radius: 2px;
background: light-dark(#ebedf0, #232529);
transition: background-color 0.15s ease calc((4 - var(--i)) * 0.05s);
}
.toggle-charge__bolt {
position: absolute;
left: 50%;
top: 50%;
width: 16px;
height: 16px;
margin: -8px 0 0 -8px;
fill: light-dark(#fbfcfd, #121417);
stroke: light-dark(#373a40, #f1f2f3);
stroke-width: 1.5;
stroke-linejoin: round;
opacity: 0;
transform: scale(0.4) rotate(-20deg);
transition: opacity 0.2s, transform 0.3s;
}
/* Cells fill left to right, then the bolt drops in and the last cell keeps charging. */
.toggle-charge__input:checked + .toggle-charge__track .toggle-charge__cell { background: light-dark(#42454c, #e5e6e9); transition-delay: calc(var(--i) * 0.09s); }
.toggle-charge__input:checked + .toggle-charge__track .toggle-charge__cell:last-of-type { animation: toggle-charge-pulse 1.2s ease-in-out 0.6s infinite; }
.toggle-charge__input:checked + .toggle-charge__track .toggle-charge__bolt { opacity: 1; transform: none; transition: opacity 0.2s 0.45s, transform 0.4s cubic-bezier(0.34, 1.8, 0.64, 1) 0.45s; }
@media (prefers-reduced-motion: reduce) {
.toggle-charge__track * { transition-duration: 0.01s !important; transition-delay: 0s !important; animation: none !important; }
}Goal: Create a "Charge" toggle.
Visual behavior: A fast-charge switch shaped like a battery: the cells fill one by one, a bolt drops in, and the last cell keeps pulsing as if still charging. Off, they drain from the right.
Technique:
- A real native checkbox with role="switch" (visually hidden: absolute, 1x1, opacity 0) inside a <label>; every visual is aria-hidden and styled from the input with :checked + sibling selectors.
- Five cells transition their background with a delay from --i when on and the reverse order when off.
- The bolt fades and springs in after the cells; the last cell pulses on a loop while on.
Accessibility: A native checkbox with role="switch" inside a <label>, so Space toggles it and screen readers announce a switch; the visible label names it and :focus-visible on the input outlines the visual. Under prefers-reduced-motion the change is instant.
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 "Charge" toggle.
Visual behavior: A fast-charge switch shaped like a battery: the cells fill one by one, a bolt drops in, and the last cell keeps pulsing as if still charging. Off, they drain from the right.
Technique:
- A real native checkbox with role="switch" (visually hidden: absolute, 1x1, opacity 0) inside a <label>; every visual is aria-hidden and styled from the input with :checked + sibling selectors.
- Five cells transition their background with a delay from --i when on and the reverse order when off.
- The bolt fades and springs in after the cells; the last cell pulses on a loop while on.
Accessibility: A native checkbox with role="switch" inside a <label>, so Space toggles it and screen readers announce a switch; the visible label names it and :focus-visible on the input outlines the visual. Under prefers-reduced-motion the change is instant.
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
A fast-charge switch shaped like a battery: the cells fill one by one, a bolt drops in, and the last cell keeps pulsing as if still charging. Off, they drain from the right.
- Dependencies
- None
- Difficulty
- Beginner
- Triggers
- click, state change, fill, delay stagger
- Techniques
- css transition, transition delay stagger, keyframes
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
A native checkbox with role="switch" inside a <label>, so Space toggles it and screen readers announce a switch; the visible label names it and :focus-visible on the input outlines the visual. Under prefers-reduced-motion the change is instant.