Signal
import { useState } from 'react';
const css = `
.slider-signal { display: grid; justify-items: center; gap: 14px; width: 220px; }
.slider-signal__bars { display: flex; align-items: flex-end; gap: 6px; height: 56px; }
.slider-signal__bar {
--on: clamp(0, calc((var(--slider-signal-v) * 5 - var(--k)) * 12), 1);
width: 12px;
height: calc(16px + var(--k) * 10px);
border-radius: 3px;
background: color-mix(in oklab, light-dark(#373a40, #f1f2f3) calc(var(--on) * 100%), light-dark(#ebedf0, #232529));
box-shadow: 0 0 calc(var(--on) * 10px) color-mix(in oklab, light-dark(#42454c, #e5e6e9) calc(var(--on) * 35%), transparent);
transform-origin: 50% 100%;
transform: scaleY(calc(0.82 + 0.18 * var(--on)));
transition: background-color 0.2s, box-shadow 0.3s, transform 0.4s cubic-bezier(0.3, 1.8, 0.5, 1);
}
.slider-signal__word { color: light-dark(#42454c, #e5e6e9); font-size: 12px; font-weight: 600; }
.slider-signal__track { position: relative; width: 100%; height: 24px; }
.slider-signal__rail { position: absolute; left: 0; right: 0; top: 10px; height: 4px; border-radius: 2px; background: light-dark(#ebedf0, #232529); }
.slider-signal__fill { position: absolute; left: 0; top: 10px; height: 4px; border-radius: 2px; width: calc(9px + var(--slider-signal-v) * (100% - 18px)); background: light-dark(#50535b, #c6c8cd); }
.slider-signal__thumb { position: absolute; top: 3px; left: calc(var(--slider-signal-v) * (100% - 18px)); width: 18px; height: 18px; border-radius: 50%; background: light-dark(#373a40, #f1f2f3); box-shadow: 0 2px 6px light-dark(rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.4)); transition: transform 0.2s; }
.slider-signal__track:active .slider-signal__thumb { transform: scale(1.2); }
.slider-signal:has(.slider-signal__input:focus-visible) .slider-signal__thumb { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; }
.slider-signal__input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; -webkit-appearance: none; appearance: none; background: none; }
.slider-signal__input::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; }
.slider-signal__input::-moz-range-thumb { width: 18px; height: 18px; border: 0; }
@media (prefers-reduced-motion: reduce) {
.slider-signal * { transition-duration: 0.01s !important; }
}
`;
const WORDS = ['No signal', 'Weak', 'Fair', 'Good', 'Strong', 'Excellent'];
export function SignalSlider() {
const [v, setV] = useState(64);
const word = WORDS[Math.ceil(v / 20)];
return (
<>
<style>
{css}
</style>
<div className="slider-signal" style={{ '--slider-signal-v': v / 100 } as React.CSSProperties}>
<span className="slider-signal__bars" aria-hidden="true">
{[0, 1, 2, 3, 4].map((k) => (
<span key={k} className="slider-signal__bar" style={{ '--k': k } as React.CSSProperties} />
))}
</span>
<span className="slider-signal__word" aria-hidden="true">
{word}
</span>
<div className="slider-signal__track">
<span className="slider-signal__rail" />
<span className="slider-signal__fill" />
<span className="slider-signal__thumb" />
<input
className="slider-signal__input"
type="range"
min={0}
max={100}
value={v}
onChange={(e) => setV(+e.target.value)}
aria-label="Signal strength"
aria-valuetext={word}
/>
</div>
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initSliderSignal(el) on the mounted element instead.
<div class="slider-signal" style="--slider-signal-v:0.64">
<span class="slider-signal__bars" aria-hidden="true">
<span class="slider-signal__bar" style="--k:0"></span>
<span class="slider-signal__bar" style="--k:1"></span>
<span class="slider-signal__bar" style="--k:2"></span>
<span class="slider-signal__bar" style="--k:3"></span>
<span class="slider-signal__bar" style="--k:4"></span>
</span>
<span class="slider-signal__word" aria-hidden="true">Strong</span>
<div class="slider-signal__track">
<span class="slider-signal__rail"></span>
<span class="slider-signal__fill"></span>
<span class="slider-signal__thumb"></span>
<input class="slider-signal__input" type="range" min="0" max="100" aria-label="Signal strength" aria-valuetext="Strong" value="64"/>
</div>
</div>.slider-signal { display: grid; justify-items: center; gap: 14px; width: 220px; }
.slider-signal__bars { display: flex; align-items: flex-end; gap: 6px; height: 56px; }
.slider-signal__bar {
--on: clamp(0, calc((var(--slider-signal-v) * 5 - var(--k)) * 12), 1);
width: 12px;
height: calc(16px + var(--k) * 10px);
border-radius: 3px;
background: color-mix(in oklab, light-dark(#373a40, #f1f2f3) calc(var(--on) * 100%), light-dark(#ebedf0, #232529));
box-shadow: 0 0 calc(var(--on) * 10px) color-mix(in oklab, light-dark(#42454c, #e5e6e9) calc(var(--on) * 35%), transparent);
transform-origin: 50% 100%;
transform: scaleY(calc(0.82 + 0.18 * var(--on)));
transition: background-color 0.2s, box-shadow 0.3s, transform 0.4s cubic-bezier(0.3, 1.8, 0.5, 1);
}
.slider-signal__word { color: light-dark(#42454c, #e5e6e9); font-size: 12px; font-weight: 600; }
.slider-signal__track { position: relative; width: 100%; height: 24px; }
.slider-signal__rail { position: absolute; left: 0; right: 0; top: 10px; height: 4px; border-radius: 2px; background: light-dark(#ebedf0, #232529); }
.slider-signal__fill { position: absolute; left: 0; top: 10px; height: 4px; border-radius: 2px; width: calc(9px + var(--slider-signal-v) * (100% - 18px)); background: light-dark(#50535b, #c6c8cd); }
.slider-signal__thumb { position: absolute; top: 3px; left: calc(var(--slider-signal-v) * (100% - 18px)); width: 18px; height: 18px; border-radius: 50%; background: light-dark(#373a40, #f1f2f3); box-shadow: 0 2px 6px light-dark(rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.4)); transition: transform 0.2s; }
.slider-signal__track:active .slider-signal__thumb { transform: scale(1.2); }
.slider-signal:has(.slider-signal__input:focus-visible) .slider-signal__thumb { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; }
.slider-signal__input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; -webkit-appearance: none; appearance: none; background: none; }
.slider-signal__input::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; }
.slider-signal__input::-moz-range-thumb { width: 18px; height: 18px; border: 0; }
@media (prefers-reduced-motion: reduce) {
.slider-signal * { transition-duration: 0.01s !important; }
}function initSliderSignal(root) {
var WORDS = ['No signal', 'Weak', 'Fair', 'Good', 'Strong', 'Excellent'];
var input = root.querySelector('.slider-signal__input');
var word = root.querySelector('.slider-signal__word');
function update() {
var v = +input.value;
var w = WORDS[Math.ceil(v / 20)];
root.style.setProperty('--slider-signal-v', v / 100);
word.textContent = w;
input.setAttribute('aria-valuetext', w);
}
input.addEventListener('input', update);
update();
return function () { input.removeEventListener('input', update); };
}
document.querySelectorAll('.slider-signal').forEach(initSliderSignal);Goal: Create a "Signal" slider.
Visual behavior: A signal-strength slider: five bars rise and light one by one as you drag, and a word for the strength changes from No signal to Excellent.
Technique:
- A real <input type="range"> lies over the drawing, transparent (opacity 0, appearance none), with its thumb hit area sized to the drawn thumb, so dragging, clicking the track and the arrow, Page Up/Down, Home and End keys all work natively. The drawing is aria-hidden.
- The value is written to one CSS custom property (0 to 1) on the root; each bar carries its index as a second property and lights once the value passes its share, with a short spring on its height.
- The word is one of six, picked from the value in steps of 20, and doubles as the aria-valuetext.
- :has(input:focus-visible) outlines the drawn thumb, so keyboard focus is visible though the input itself is not.
Accessibility: A native range input with an aria-label and an aria-valuetext in words, so a screen reader announces the reading rather than a bare number; keyboard focus outlines the drawn thumb. Under prefers-reduced-motion the bars switch without transitions.
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 "Signal" slider.
Visual behavior: A signal-strength slider: five bars rise and light one by one as you drag, and a word for the strength changes from No signal to Excellent.
Technique:
- A real <input type="range"> lies over the drawing, transparent (opacity 0, appearance none), with its thumb hit area sized to the drawn thumb, so dragging, clicking the track and the arrow, Page Up/Down, Home and End keys all work natively. The drawing is aria-hidden.
- The value is written to one CSS custom property (0 to 1) on the root; each bar carries its index as a second property and lights once the value passes its share, with a short spring on its height.
- The word is one of six, picked from the value in steps of 20, and doubles as the aria-valuetext.
- :has(input:focus-visible) outlines the drawn thumb, so keyboard focus is visible though the input itself is not.
Accessibility: A native range input with an aria-label and an aria-valuetext in words, so a screen reader announces the reading rather than a bare number; keyboard focus outlines the drawn thumb. Under prefers-reduced-motion the bars switch without transitions.
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 signal-strength slider: five bars rise and light one by one as you drag, and a word for the strength changes from No signal to Excellent.
- Dependencies
- None
- Difficulty
- Beginner
- Triggers
- state change, delay stagger, fill
- Techniques
- css variables, css transition
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
A native range input with an aria-label and an aria-valuetext in words, so a screen reader announces the reading rather than a bare number; keyboard focus outlines the drawn thumb. Under prefers-reduced-motion the bars switch without transitions.