Circuit
const css = `
.toggle-circuit { position: relative; display: inline-flex; align-items: center; gap: 12px; color: light-dark(#42454c, #e5e6e9); font-size: 14px; cursor: pointer; user-select: none; }
.toggle-circuit__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.toggle-circuit__track {
position: relative;
width: 86px;
height: 34px;
border-radius: 9px;
background: light-dark(#f3f4f7, #1a1c1f);
box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035);
overflow: hidden;
}
.toggle-circuit__input:focus-visible + .toggle-circuit__track { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 3px; }
.toggle-circuit__board { position: absolute; inset: 0; width: 86px; height: 34px; }
.toggle-circuit__board path { fill: none; stroke-width: 1.5; stroke-linejoin: round; }
.toggle-circuit__dim { stroke: light-dark(#dbdde1, #2e3035); }
.toggle-circuit__lit {
stroke: light-dark(#373a40, #f1f2f3);
stroke-dasharray: 1;
stroke-dashoffset: 1;
filter: drop-shadow(0 0 2px light-dark(#50535b, #c6c8cd));
transition: stroke-dashoffset 0.25s ease;
}
.toggle-circuit__led { fill: light-dark(#dbdde1, #2e3035); transition: fill 0.2s; }
.toggle-circuit__chip {
position: absolute;
left: 5px;
top: 9px;
width: 26px;
height: 16px;
border-radius: 3px;
background: light-dark(#dbdde1, #2e3035);
box-shadow: inset 0 0 0 1px light-dark(#6d7179, #7d8087);
transition: transform 0.5s cubic-bezier(0.65, 0, 0.35, 1), background-color 0.3s;
}
/* Pins along the top and bottom edges. */
.toggle-circuit__chip::before, .toggle-circuit__chip::after {
content: '';
position: absolute;
left: 3px;
right: 3px;
height: 3px;
background: repeating-linear-gradient(90deg, light-dark(#5f626a, #a7abb2) 0 2px, transparent 2px 5px);
}
.toggle-circuit__chip::before { top: -3px; }
.toggle-circuit__chip::after { bottom: -3px; }
.toggle-circuit__dot { position: absolute; left: 4px; top: 4px; width: 4px; height: 4px; border-radius: 50%; background: light-dark(#6d7179, #7d8087); transition: background-color 0.2s, box-shadow 0.2s; }
.toggle-circuit__input:checked + .toggle-circuit__track .toggle-circuit__chip { transform: translateX(50px); background: light-dark(#cbced3, #393c41); }
.toggle-circuit__input:checked + .toggle-circuit__track .toggle-circuit__dot { background: light-dark(#373a40, #f1f2f3); box-shadow: 0 0 5px light-dark(#42454c, #e5e6e9); transition-delay: 0.45s; }
.toggle-circuit__input:checked + .toggle-circuit__track .toggle-circuit__lit { stroke-dashoffset: 0; transition: stroke-dashoffset 0.6s ease var(--d); }
.toggle-circuit__input:checked + .toggle-circuit__track .toggle-circuit__led { fill: light-dark(#373a40, #f1f2f3); transition-delay: 0.9s; }
@media (prefers-reduced-motion: reduce) {
.toggle-circuit__track *, .toggle-circuit__board * { transition-duration: 0.01s !important; transition-delay: 0s !important; }
}
`;
const TRACES = ['M4 7 H22 L28 13 H56 L62 7 H76', 'M4 27 H18 L24 21 H60 L66 27 H76'];
export function CircuitToggle() {
return (
<>
<style>
{css}
</style>
<label className="toggle-circuit">
<input className="toggle-circuit__input" type="checkbox" role="switch" />
<span className="toggle-circuit__track" aria-hidden="true">
<svg className="toggle-circuit__board" viewBox="0 0 86 34">
{TRACES.map((d) => (
<path key={d} className="toggle-circuit__dim" d={d} />
))}
{TRACES.map((d, i) => (
<path key={d} className="toggle-circuit__lit" d={d} pathLength={1} style={{ '--d': `${0.2 + i * 0.12}s` } as React.CSSProperties} />
))}
<circle className="toggle-circuit__led" cx="79.5" cy="7" r="2.5" />
<circle className="toggle-circuit__led" cx="79.5" cy="27" r="2.5" />
</svg>
<span className="toggle-circuit__chip">
<span className="toggle-circuit__dot" />
</span>
</span>
Circuit
</label>
</>
);
}Markup where the component goes, CSS in your stylesheet. No JavaScript.
<label class="toggle-circuit"><input class="toggle-circuit__input" type="checkbox" role="switch"/><span class="toggle-circuit__track" aria-hidden="true"><svg class="toggle-circuit__board" viewBox="0 0 86 34"><path class="toggle-circuit__dim" d="M4 7 H22 L28 13 H56 L62 7 H76"></path><path class="toggle-circuit__dim" d="M4 27 H18 L24 21 H60 L66 27 H76"></path><path class="toggle-circuit__lit" d="M4 7 H22 L28 13 H56 L62 7 H76" pathLength="1" style="--d:0.2s"></path><path class="toggle-circuit__lit" d="M4 27 H18 L24 21 H60 L66 27 H76" pathLength="1" style="--d:0.32s"></path><circle class="toggle-circuit__led" cx="79.5" cy="7" r="2.5"></circle><circle class="toggle-circuit__led" cx="79.5" cy="27" r="2.5"></circle></svg><span class="toggle-circuit__chip"><span class="toggle-circuit__dot"></span></span></span>Circuit</label>.toggle-circuit { position: relative; display: inline-flex; align-items: center; gap: 12px; color: light-dark(#42454c, #e5e6e9); font-size: 14px; cursor: pointer; user-select: none; }
.toggle-circuit__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.toggle-circuit__track {
position: relative;
width: 86px;
height: 34px;
border-radius: 9px;
background: light-dark(#f3f4f7, #1a1c1f);
box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035);
overflow: hidden;
}
.toggle-circuit__input:focus-visible + .toggle-circuit__track { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 3px; }
.toggle-circuit__board { position: absolute; inset: 0; width: 86px; height: 34px; }
.toggle-circuit__board path { fill: none; stroke-width: 1.5; stroke-linejoin: round; }
.toggle-circuit__dim { stroke: light-dark(#dbdde1, #2e3035); }
.toggle-circuit__lit {
stroke: light-dark(#373a40, #f1f2f3);
stroke-dasharray: 1;
stroke-dashoffset: 1;
filter: drop-shadow(0 0 2px light-dark(#50535b, #c6c8cd));
transition: stroke-dashoffset 0.25s ease;
}
.toggle-circuit__led { fill: light-dark(#dbdde1, #2e3035); transition: fill 0.2s; }
.toggle-circuit__chip {
position: absolute;
left: 5px;
top: 9px;
width: 26px;
height: 16px;
border-radius: 3px;
background: light-dark(#dbdde1, #2e3035);
box-shadow: inset 0 0 0 1px light-dark(#6d7179, #7d8087);
transition: transform 0.5s cubic-bezier(0.65, 0, 0.35, 1), background-color 0.3s;
}
/* Pins along the top and bottom edges. */
.toggle-circuit__chip::before, .toggle-circuit__chip::after {
content: '';
position: absolute;
left: 3px;
right: 3px;
height: 3px;
background: repeating-linear-gradient(90deg, light-dark(#5f626a, #a7abb2) 0 2px, transparent 2px 5px);
}
.toggle-circuit__chip::before { top: -3px; }
.toggle-circuit__chip::after { bottom: -3px; }
.toggle-circuit__dot { position: absolute; left: 4px; top: 4px; width: 4px; height: 4px; border-radius: 50%; background: light-dark(#6d7179, #7d8087); transition: background-color 0.2s, box-shadow 0.2s; }
.toggle-circuit__input:checked + .toggle-circuit__track .toggle-circuit__chip { transform: translateX(50px); background: light-dark(#cbced3, #393c41); }
.toggle-circuit__input:checked + .toggle-circuit__track .toggle-circuit__dot { background: light-dark(#373a40, #f1f2f3); box-shadow: 0 0 5px light-dark(#42454c, #e5e6e9); transition-delay: 0.45s; }
.toggle-circuit__input:checked + .toggle-circuit__track .toggle-circuit__lit { stroke-dashoffset: 0; transition: stroke-dashoffset 0.6s ease var(--d); }
.toggle-circuit__input:checked + .toggle-circuit__track .toggle-circuit__led { fill: light-dark(#373a40, #f1f2f3); transition-delay: 0.9s; }
@media (prefers-reduced-motion: reduce) {
.toggle-circuit__track *, .toggle-circuit__board * { transition-duration: 0.01s !important; transition-delay: 0s !important; }
}Goal: Create a "Circuit" toggle.
Visual behavior: A circuit switch: a chip slides into place on a small board, current runs along the traces from it, and the LEDs at the end light up.
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.
- The board is an SVG of two right-angled traces drawn twice: dim, and a bright copy with pathLength 1 whose dashoffset transitions to 0 when on, one trace slightly after the other.
- The chip is a box with pins from ::before / ::after repeating gradients; it slides across and its status dot lights after it lands; the LEDs light last.
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 "Circuit" toggle.
Visual behavior: A circuit switch: a chip slides into place on a small board, current runs along the traces from it, and the LEDs at the end light up.
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.
- The board is an SVG of two right-angled traces drawn twice: dim, and a bright copy with pathLength 1 whose dashoffset transitions to 0 when on, one trace slightly after the other.
- The chip is a box with pins from ::before / ::after repeating gradients; it slides across and its status dot lights after it lands; the LEDs light last.
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 circuit switch: a chip slides into place on a small board, current runs along the traces from it, and the LEDs at the end light up.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- click, state change, draw
- Techniques
- svg stroke, stroke dashoffset, transition delay stagger
- 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.