Number stepper
A number with − and + buttons. Put a number field in .stepper: momo.js adds the buttons, keeps the value inside min and max, and keeps counting while a button is held.
Basic
<div class="stepper">
<input type="number" min="0" max="20" value="1" aria-label="Quantity">
</div>Steps and decimals
Use step for bigger jumps or decimals. Typed values outside the limits are pulled back in.
<div class="stepper">
<input type="number" min="0" max="100" step="5" value="25" aria-label="Percent">
</div>
<div class="stepper">
<input type="number" min="0" max="5" step="0.5" value="1.5" aria-label="Hours">
</div>With a label
Up to 12 people.
<div class="form-field">
<label class="form-label" for="st-guests">Guests</label>
<div class="stepper">
<input id="st-guests" type="number" min="1" max="12" value="2">
</div>
<p class="form-hint">Up to 12 people.</p>
</div>Round
.stepper-round drops the outer box and uses round buttons. Inside a .stepper-field it makes a full-width row with the label on the left.
<div class="stepper stepper-round">
<input type="number" min="0" max="9" value="1" aria-label="Tickets">
</div>
<hr>
<label class="stepper-field">
<span>Choose amount</span>
<span class="stepper stepper-round">
<input type="number" min="1" max="99" value="1" aria-label="Amount">
</span>
</label>Sizes and colors
<div class="stepper stepper-sm">
<input type="number" min="0" value="3" aria-label="Small">
</div>
<div class="stepper">
<input type="number" min="0" value="3" aria-label="Default">
</div>
<div class="stepper stepper-lg stepper-brand">
<input type="number" min="0" value="3" aria-label="Large">
</div><div class="stepper stepper-block">
<input type="number" min="0" max="50" value="10" aria-label="Seats">
</div>Disabled
<div class="stepper">
<input type="number" value="4" disabled aria-label="Locked">
</div>Your own buttons
Write the buttons yourself to change icons or labels: give them data-momo-step="-1" and data-momo-step="1".
<div class="stepper">
<button class="stepper-btn" type="button" data-momo-step="-1" aria-label="Remove one"><i class="mi mi-circle-minus"></i></button>
<input type="number" min="0" max="10" value="5" aria-label="Items">
<button class="stepper-btn" type="button" data-momo-step="1" aria-label="Add one"><i class="mi mi-circle-plus"></i></button>
</div>Accessibility
- Give the field a label (
<label for>oraria-label). - Keyboard and screen reader users change the number in the field with ↑ ↓; the buttons are skipped by Tab so there is one stop, not three.
- The field fires
inputon every step andchangewhen you let go.
Variables
| Variable | Default |
|---|---|
--stepper-height | 2.75rem (buttons are square) |
--stepper-btn-bg | Paper (brand with .stepper-brand) |