Skip to content

Quantity Stepper

A copy-paste css-only interactions component in pure HTML & CSS. Zero dependencies, framework-agnostic, MIT-licensed.

CSS-Only InteractionsHTMLCSSany framework

Copy into your project

HTML
<!-- Quantity Stepper — a hidden radio group holds the current value;
     arrow keys move it natively, and each +/- label points at the
     adjacent radio id. Zero JS. -->
<div class="nuda-co2-qty-stepper" role="group" aria-label="Quantity">
  <input class="nuda-co2-qty-stepper__input" type="radio" name="nuda-co2-qty" id="co2-qty-1" aria-label="Quantity 1" />
  <input class="nuda-co2-qty-stepper__input" type="radio" name="nuda-co2-qty" id="co2-qty-2" aria-label="Quantity 2" checked />
  <input class="nuda-co2-qty-stepper__input" type="radio" name="nuda-co2-qty" id="co2-qty-3" aria-label="Quantity 3" />

  <div class="nuda-co2-qty-stepper__control" data-n="1">
    <span class="nuda-co2-qty-stepper__btn nuda-co2-qty-stepper__btn--disabled" aria-hidden="true">&#8722;</span>
    <span class="nuda-co2-qty-stepper__value">1</span>
    <label class="nuda-co2-qty-stepper__btn" for="co2-qty-2">&#43;</label>
  </div>
  <div class="nuda-co2-qty-stepper__control" data-n="2">
    <label class="nuda-co2-qty-stepper__btn" for="co2-qty-1">&#8722;</label>
    <span class="nuda-co2-qty-stepper__value">2</span>
    <label class="nuda-co2-qty-stepper__btn" for="co2-qty-3">&#43;</label>
  </div>
  <div class="nuda-co2-qty-stepper__control" data-n="3">
    <label class="nuda-co2-qty-stepper__btn" for="co2-qty-2">&#8722;</label>
    <span class="nuda-co2-qty-stepper__value">3</span>
    <span class="nuda-co2-qty-stepper__btn nuda-co2-qty-stepper__btn--disabled" aria-hidden="true">&#43;</span>
  </div>
</div>
CSS
.nuda-co2-qty-stepper {
  --nuda-co2-qs-accent: #e4ff54;
  font-family: inherit;
}

.nuda-co2-qty-stepper__input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.nuda-co2-qty-stepper__control {
  display: none;
  align-items: center;
  gap: 10px;
}

#co2-qty-1:checked~.nuda-co2-qty-stepper__control[data-n="1"], #co2-qty-2:checked~.nuda-co2-qty-stepper__control[data-n="2"], #co2-qty-3:checked~.nuda-co2-qty-stepper__control[data-n="3"] {
  display: flex;
}

.nuda-co2-qty-stepper__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #09090b;
  background: var(--nuda-co2-qs-accent);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  transition: transform .15s ease,opacity .2s ease;
}

.nuda-co2-qty-stepper__btn:hover {
  transform: translateY(-1px);
}

.nuda-co2-qty-stepper__btn--disabled {
  opacity: .3;
  pointer-events: none;
  background: rgba(255,255,255,.08);
  color: #666;
}

.nuda-co2-qty-stepper__value {
  min-width: 34px;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  border-radius: 6px;
}

#co2-qty-1:focus-visible~.nuda-co2-qty-stepper__control[data-n="1"] .nuda-co2-qty-stepper__value, #co2-qty-2:focus-visible~.nuda-co2-qty-stepper__control[data-n="2"] .nuda-co2-qty-stepper__value, #co2-qty-3:focus-visible~.nuda-co2-qty-stepper__control[data-n="3"] .nuda-co2-qty-stepper__value {
  outline: 2px solid var(--nuda-co2-qs-accent);
  outline-offset: 3px;
}

@media (prefers-reduced-motion:reduce) {
  .nuda-co2-qty-stepper__btn {
    transition: none;
  }
}

How to use Quantity Stepper

Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.

Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.

More css-only interactions components

← Browse all NudaUI components