∞ forever components

Inputs & Switches

Segmented Control

Slate-to-sage pill slides between four native segment buttons with elastic spring stretch. First input stops automatic cycling; committed selection remains.

cssmedium complexitymoderate motionclickmobile-ready

Open on the canvas to copy the code → Free account · 3 copies a day · membership goes unlimited

Live demo — the real component, running in a sandbox. One self-contained HTML file, zero dependencies. Open it on the canvas →
1

When to use it

Date-range pickers, tab bars, filter controls in dark-themed dashboards or app UIs.

When not to

Production use without removing the auto-cycle loop. Light-background UIs where the hardcoded dark background clashes.

Working with an AI agent

Every component ships agent-ready metadata. An example instruction for this one:

Change options to ['S','M','T','W'] in .c04-opt native buttons, set pill gradient to linear-gradient(135deg,#f97316,#ec4899), slow spring by changing k from 0.18 to 0.10. Theme: dark tokens live in :root, the light variant in :root[data-theme="light"]; ?theme=light or a {type:'forever:theme'} postMessage switches at runtime.

Safe to edit

  • option labels (Day/Week/Month/Year in .opt divs)
  • pill gradient colors (#4B5560, #5A8C73)
  • spring stiffness (k=0.18) and damping (damp=0.65)
  • auto-cycle interval (auto>75)
  • pill stretch multiplier (vel*40)
  • theme tokens (:root dark defaults + [data-theme=light] overrides)

Keep intact

  • geometry cache (geoms array, measure() on resize only)
  • visibilitychange pause guard
  • IIFE wrapper
  • prefers-reduced-motion check
  • theme hook (?theme= bootstrap + forever:theme message listener + theme tokens)
  • demo-v1 preview lifecycle: initialize demoEnabled from window.__foreverPreview and stop attract work on the window forever:interactive event; retain manual feedback, settling, cleanup and explicit sessions

Known limitations

  • First deliberate input permanently disables idle demo; manual input, finite feedback and settling remain active. Host demoEnabled=false skips the initial attract cycle.
  • Light re-theme via the [data-theme=light] token block; catalog bg/accent describe the dark default
  • No aria-selected or role=tablist — add for full accessibility
  • State remains local to each mounted instance; format/theme remount preserves takeover, not component values.

segmented-controlpillspringui-controlgradientauto-cycletabs

More Inputs & Switches components

  • Liquid ToggleSVG liquid toggle with a goo filter, trailing droplets and a native button. First deliberate input stops the idle demo; the chosen on/off state settles fully.
  • Glow SliderSVG range slider with a muted plum-to-teal fill, glow and value bubble, driven by a native range input. First input stops demo oscillation; drag and…
  • Spring StepperMint stepper with native minus/plus buttons and a number reel that settles with spring feedback. First deliberate input stops automatic steps; the chosen…
  • Checkbox MorphThree native amber checkbox buttons animate their check strokes and expose pressed state. First input stops the demo; checked values remain.
  • Star RatingFive gold SVG star radio controls commit ratings on click or keyboard input and settle with a scale bounce. First input stops automatic sweeping.
  • OTP BoxesFour native numeric OTP inputs support typing, paste, focus advance and Backspace navigation. Initial digits are populated; first input stops scripted entry.