Number Input Examples
The examples below assume that you have imported the component and set up the theme.
Basic
Take a number in a form. value sets the starting number, name submits it, and min, max, and step set the limits and the step size.
--empty
<form class="number-input-basic"> <label for="number-input-width">Width</label> <sv-number-input id="number-input-width" max="3840" min="320" name="width" step="8" value="1024" ></sv-number-input></form>
<script type="application/x-typescript" module> const form = document.querySelector<HTMLFormElement>(".number-input-basic")!;
form.addEventListener("submit", event => event.preventDefault());</script>
<style> .number-input-basic { display: grid; gap: 0.5em; justify-items: center;
label { font-weight: 600; } }</style>Formatting
Show the value with a currency sign, a percent sign, or a unit. prefix and suffix add text that stays in place while the user types, decimals fixes the number of decimals, and no-grouping drops the group separators.
<div class="number-input-formatting"> <div class="variant"> <label for="number-input-price">Price</label> <sv-number-input id="number-input-price" decimals="2" min="0" prefix="$" step="0.5" value="1299.99" ></sv-number-input> <span>prefix="$" decimals="2"</span> </div>
<div class="variant"> <label for="number-input-discount">Discount</label> <sv-number-input id="number-input-discount" max="100" min="0" step="5" suffix="%" value="25" ></sv-number-input> <span>suffix="%"</span> </div>
<div class="variant"> <label for="number-input-weight">Weight</label> <sv-number-input id="number-input-weight" min="0" step="0.1" suffix=" kg" value="72.5" ></sv-number-input> <span>suffix=" kg"</span> </div>
<div class="variant"> <label for="number-input-year">Year</label> <sv-number-input id="number-input-year" max="2100" min="1900" no-grouping value="2024" ></sv-number-input> <span>no-grouping</span> </div></div>
<style> .number-input-formatting { display: grid; gap: 1.5em; justify-items: center;
.variant { display: grid; gap: 0.4em; justify-items: center;
label { font-weight: 600; }
span { font-size: 0.8em; color: var(--sv-gray-3); } } }</style>