Notch
import { useState } from 'react';
const SIZES = ['XS', 'S', 'M', 'L', 'XL'];
const css = `
@keyframes slider-notch-click-a { 0% { transform: scale(1); } 30% { transform: scale(0.82); } 100% { transform: scale(1); } }
@keyframes slider-notch-click-b { 0% { transform: scale(1); } 30% { transform: scale(0.82); } 100% { transform: scale(1); } }
.slider-notch { display: grid; gap: 8px; width: 220px; }
.slider-notch__track { position: relative; height: 28px; }
.slider-notch__rail { position: absolute; left: 12px; right: 12px; top: 12px; height: 4px; border-radius: 2px; background: light-dark(#ebedf0, #232529); }
.slider-notch__fill { position: absolute; left: 12px; top: 12px; height: 4px; border-radius: 2px; width: calc(var(--slider-notch-v) * (100% - 24px)); background: light-dark(#50535b, #c6c8cd); transition: width 0.4s cubic-bezier(0.3, 1.8, 0.5, 1); }
.slider-notch__stop { --on: clamp(0, calc((var(--slider-notch-v) * 4 - var(--k)) * 10 + 1), 1); position: absolute; top: 9px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: color-mix(in oklab, light-dark(#50535b, #c6c8cd) calc(var(--on) * 100%), light-dark(#ebedf0, #232529)); box-shadow: 0 0 0 3px light-dark(#fbfcfd, #121417); transition: background-color 0.2s; }
.slider-notch__thumb { position: absolute; top: 2px; left: calc(var(--slider-notch-v) * (100% - 24px)); width: 24px; height: 24px; transition: left 0.4s cubic-bezier(0.3, 1.8, 0.5, 1); }
.slider-notch__knob { display: block; width: 100%; height: 100%; border-radius: 50%; background: light-dark(#373a40, #f1f2f3); box-shadow: inset 0 -2px 0 light-dark(#50535b, #c6c8cd), 0 3px 8px light-dark(rgba(0, 0, 0, 0.14), rgba(0, 0, 0, 0.45)); }
.slider-notch[data-flip='a'] .slider-notch__knob { animation: slider-notch-click-a 0.3s ease-out; }
.slider-notch[data-flip='b'] .slider-notch__knob { animation: slider-notch-click-b 0.3s ease-out; }
.slider-notch:has(.slider-notch__input:focus-visible) .slider-notch__knob { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; }
.slider-notch__labels { position: relative; height: 16px; }
.slider-notch__label { position: absolute; width: 30px; margin-left: -15px; color: light-dark(#6d7179, #7d8087); font-size: 11px; font-weight: 600; text-align: center; transition: color 0.2s, transform 0.3s cubic-bezier(0.3, 1.8, 0.5, 1); }
.slider-notch__label[data-on] { color: light-dark(#373a40, #f1f2f3); transform: translateY(-1px) scale(1.1); }
.slider-notch__input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; -webkit-appearance: none; appearance: none; background: none; }
.slider-notch__input::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; }
.slider-notch__input::-moz-range-thumb { width: 24px; height: 24px; border: 0; }
@media (prefers-reduced-motion: reduce) {
.slider-notch * { transition-duration: 0.01s !important; animation: none !important; }
}
`;
export function NotchSlider() {
const [i, setI] = useState(2);
const [flip, setFlip] = useState(0);
return (
<>
<style>
{css}
</style>
<div className="slider-notch" data-flip={flip ? (flip % 2 ? 'a' : 'b') : undefined} style={{ '--slider-notch-v': i / 4 } as React.CSSProperties}>
<div className="slider-notch__track">
<span className="slider-notch__rail" />
<span className="slider-notch__fill" />
{SIZES.map((s, k) => (
<span key={s} className="slider-notch__stop" style={{ left: `calc(12px + ${k / 4} * (100% - 24px))`, '--k': k } as React.CSSProperties} />
))}
<span className="slider-notch__thumb">
<span className="slider-notch__knob" />
</span>
<input
className="slider-notch__input"
type="range"
min={0}
max={4}
value={i}
onChange={(e) => {
setI(+e.target.value);
setFlip((f) => f + 1);
}}
aria-label="Size"
aria-valuetext={SIZES[i]}
/>
</div>
<div className="slider-notch__labels" aria-hidden="true">
{SIZES.map((s, k) => (
<span key={s} className="slider-notch__label" data-on={k === i ? '' : undefined} style={{ left: `calc(12px + ${k / 4} * (100% - 24px))` }}>
{s}
</span>
))}
</div>
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initSliderNotch(el) on the mounted element instead.
<div class="slider-notch" style="--slider-notch-v:0.5">
<div class="slider-notch__track">
<span class="slider-notch__rail"></span>
<span class="slider-notch__fill"></span>
<span class="slider-notch__stop" style="left:calc(12px + 0 * (100% - 24px));--k:0"></span>
<span class="slider-notch__stop" style="left:calc(12px + 0.25 * (100% - 24px));--k:1"></span>
<span class="slider-notch__stop" style="left:calc(12px + 0.5 * (100% - 24px));--k:2"></span>
<span class="slider-notch__stop" style="left:calc(12px + 0.75 * (100% - 24px));--k:3"></span>
<span class="slider-notch__stop" style="left:calc(12px + 1 * (100% - 24px));--k:4"></span>
<span class="slider-notch__thumb">
<span class="slider-notch__knob"></span>
</span>
<input class="slider-notch__input" type="range" min="0" max="4" aria-label="Size" aria-valuetext="M" value="2"/>
</div>
<div class="slider-notch__labels" aria-hidden="true">
<span class="slider-notch__label" style="left:calc(12px + 0 * (100% - 24px))">XS</span>
<span class="slider-notch__label" style="left:calc(12px + 0.25 * (100% - 24px))">S</span>
<span class="slider-notch__label" data-on="" style="left:calc(12px + 0.5 * (100% - 24px))">M</span>
<span class="slider-notch__label" style="left:calc(12px + 0.75 * (100% - 24px))">L</span>
<span class="slider-notch__label" style="left:calc(12px + 1 * (100% - 24px))">XL</span>
</div>
</div>@keyframes slider-notch-click-a { 0% { transform: scale(1); } 30% { transform: scale(0.82); } 100% { transform: scale(1); } }
@keyframes slider-notch-click-b { 0% { transform: scale(1); } 30% { transform: scale(0.82); } 100% { transform: scale(1); } }
.slider-notch { display: grid; gap: 8px; width: 220px; }
.slider-notch__track { position: relative; height: 28px; }
.slider-notch__rail { position: absolute; left: 12px; right: 12px; top: 12px; height: 4px; border-radius: 2px; background: light-dark(#ebedf0, #232529); }
.slider-notch__fill { position: absolute; left: 12px; top: 12px; height: 4px; border-radius: 2px; width: calc(var(--slider-notch-v) * (100% - 24px)); background: light-dark(#50535b, #c6c8cd); transition: width 0.4s cubic-bezier(0.3, 1.8, 0.5, 1); }
.slider-notch__stop { --on: clamp(0, calc((var(--slider-notch-v) * 4 - var(--k)) * 10 + 1), 1); position: absolute; top: 9px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: color-mix(in oklab, light-dark(#50535b, #c6c8cd) calc(var(--on) * 100%), light-dark(#ebedf0, #232529)); box-shadow: 0 0 0 3px light-dark(#fbfcfd, #121417); transition: background-color 0.2s; }
.slider-notch__thumb { position: absolute; top: 2px; left: calc(var(--slider-notch-v) * (100% - 24px)); width: 24px; height: 24px; transition: left 0.4s cubic-bezier(0.3, 1.8, 0.5, 1); }
.slider-notch__knob { display: block; width: 100%; height: 100%; border-radius: 50%; background: light-dark(#373a40, #f1f2f3); box-shadow: inset 0 -2px 0 light-dark(#50535b, #c6c8cd), 0 3px 8px light-dark(rgba(0, 0, 0, 0.14), rgba(0, 0, 0, 0.45)); }
.slider-notch[data-flip='a'] .slider-notch__knob { animation: slider-notch-click-a 0.3s ease-out; }
.slider-notch[data-flip='b'] .slider-notch__knob { animation: slider-notch-click-b 0.3s ease-out; }
.slider-notch:has(.slider-notch__input:focus-visible) .slider-notch__knob { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; }
.slider-notch__labels { position: relative; height: 16px; }
.slider-notch__label { position: absolute; width: 30px; margin-left: -15px; color: light-dark(#6d7179, #7d8087); font-size: 11px; font-weight: 600; text-align: center; transition: color 0.2s, transform 0.3s cubic-bezier(0.3, 1.8, 0.5, 1); }
.slider-notch__label[data-on] { color: light-dark(#373a40, #f1f2f3); transform: translateY(-1px) scale(1.1); }
.slider-notch__input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; -webkit-appearance: none; appearance: none; background: none; }
.slider-notch__input::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; }
.slider-notch__input::-moz-range-thumb { width: 24px; height: 24px; border: 0; }
@media (prefers-reduced-motion: reduce) {
.slider-notch * { transition-duration: 0.01s !important; animation: none !important; }
}function initSliderNotch(root) {
var SIZES = ['XS', 'S', 'M', 'L', 'XL'];
var input = root.querySelector('.slider-notch__input');
var labels = root.querySelectorAll('.slider-notch__label');
var flip = 0;
function update() {
var i = +input.value;
root.style.setProperty('--slider-notch-v', i / 4);
// Each step flips data-flip between a and b, so the click-in keyframes restart every time.
flip += 1;
root.setAttribute('data-flip', flip % 2 ? 'a' : 'b');
labels.forEach(function (label, k) { label.toggleAttribute('data-on', k === i); });
input.setAttribute('aria-valuetext', SIZES[i]);
}
input.addEventListener('input', update);
return function () { input.removeEventListener('input', update); };
}
document.querySelectorAll('.slider-notch').forEach(initSliderNotch);Goal: Create a "Notch" slider.
Visual behavior: A size picker with five detents: the thumb clicks into each notch with a little overshoot, the notch pulses and the chosen size label lifts.
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 input steps 0 to 4, so it can only rest on a notch.
- The value is written to one CSS custom property (0 to 1) on the root; the thumb sits at the chosen stop on an overshooting curve.
- The click pulse should replay on every step, so it alternates between two identically written keyframes, chosen by a data-flip attribute that flips between a and b on each change.
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 thumb moves without overshoot and nothing pulses.
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 "Notch" slider.
Visual behavior: A size picker with five detents: the thumb clicks into each notch with a little overshoot, the notch pulses and the chosen size label lifts.
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 input steps 0 to 4, so it can only rest on a notch.
- The value is written to one CSS custom property (0 to 1) on the root; the thumb sits at the chosen stop on an overshooting curve.
- The click pulse should replay on every step, so it alternates between two identically written keyframes, chosen by a data-flip attribute that flips between a and b on each change.
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 thumb moves without overshoot and nothing pulses.
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 size picker with five detents: the thumb clicks into each notch with a little overshoot, the notch pulses and the chosen size label lifts.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- state change, spring, click
- Techniques
- css variables, keyframes, 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 thumb moves without overshoot and nothing pulses.