Spin Button
2 Spin Button variations from the W3C ARIA Authoring Practices Guide.
Spin Button (Date Picker, Deprecated)
This reproduces the deprecated APG date spinbutton example with labeled day, month, and year fields. Month lengths and leap years constrain the day; the complete date labels the group.
W3C marks this example as deprecated. It is included for comparison; use the current alternative when building new interfaces.
Example
Choose a date
Wednesday, January 31, 2024
Keyboard interaction
Up/Down changes one step, Page Up/Down changes five steps, and Home/End selects the minimum/maximum. You can also type a number. Invalid edits are marked and corrected when committed. Day and month wrap at their boundaries, including five-step Page Up/Down changes.
Events
Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.
axxy-spinbutton-change— Dispatched when the spinbutton value changes. (target:<input type="number"> / [role="spinbutton"], detail:{ value: number })input / change— Standard numeric input and change events. (target:<input type="number"> / [role="spinbutton"], detail:Native Event)
Example HTML
<axxy-scope>
<h2 id="date-label">Choose a date</h2>
<p id="date-value">Wednesday, January 31, 2024</p>
<div role="group" aria-labelledby="date-label date-value">
<div class="spin-field">
<label for="date-day">Day</label>
<button type="button" aria-label="Previous day">−</button>
<input id="date-day" type="number" min="1" max="31" step="1" value="31">
<button type="button" aria-label="Next day">+</button>
</div>
<div class="spin-field">
<label for="date-month">Month</label>
<button type="button" aria-label="Previous month">−</button>
<input id="date-month" type="number" min="1" max="12" step="1" value="1">
<button type="button" aria-label="Next month">+</button>
</div>
<div class="spin-field">
<label for="date-year">Year</label>
<button type="button" aria-label="Previous year">−</button>
<input id="date-year" type="number" min="1900" max="2100" step="1" value="2024">
<button type="button" aria-label="Next year">+</button>
</div>
</div>
</axxy-scope>Spin Button (Quantity)
Editable quantity fields validate numeric input and expose their bounds. Adjacent increase/decrease buttons provide pointer, touch, and voice access and announce changes.
Example
Keyboard interaction
Up/Down changes one step, Page Up/Down changes five steps, and Home/End selects the minimum/maximum. You can also type a number. Invalid edits are marked and corrected when committed.
Events
Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.
axxy-spinbutton-change— Dispatched when the spinbutton value changes. (target:<input type="number"> / [role="spinbutton"], detail:{ value: number })input / change— Standard numeric input and change events. (target:<input type="number"> / [role="spinbutton"], detail:Native Event)
Example HTML
<axxy-scope>
<fieldset>
<legend>Guests</legend>
<div class="spin-field">
<label for="adults">Adults</label>
<div>
<button type="button" aria-label="Remove adult" title="Remove adult">−</button>
<input id="adults" role="spinbutton" type="text" inputmode="numeric" aria-valuemin="1" aria-valuemax="8" aria-errormessage="adults-error" value="1" size="3">
<button type="button" aria-label="Add adult" title="Add adult">+</button>
</div>
<p>1 to 8</p>
<p id="adults-error" hidden>Enter a whole number between 1 and 8.</p>
</div>
<div class="spin-field">
<label for="kids">Kids</label>
<div>
<button type="button" aria-label="Remove child" title="Remove child">−</button>
<input id="kids" role="spinbutton" type="text" inputmode="numeric" aria-valuemin="0" aria-valuemax="8" aria-errormessage="kids-error" value="0" size="3">
<button type="button" aria-label="Add child" title="Add child">+</button>
</div>
<p>0 to 8</p>
<p id="kids-error" hidden>Enter a whole number between 0 and 8.</p>
</div>
<div class="spin-field">
<label for="animals">Animals</label>
<div>
<button type="button" aria-label="Remove animal" title="Remove animal">−</button>
<input id="animals" role="spinbutton" type="text" inputmode="numeric" aria-valuemin="0" aria-valuemax="12" aria-errormessage="animals-error" value="0" size="3">
<button type="button" aria-label="Add animal" title="Add animal">+</button>
</div>
<p>0 to 12</p>
<p id="animals-error" hidden>Enter a whole number between 0 and 12.</p>
</div>
</fieldset>
<p role="status" data-quantity-status></p>
</axxy-scope>