Skip to main content

Number field

The number field component captures numeric input with built-in number validation. Use it to collect quantities, prices, or other numeric information.

The component supports min/max constraints and step increments for guided numeric entry. For monetary values with currency formatting, use money field.


Configure the following properties on the number field component.

Anchor to value
value
string
required

The current numeric value in the field as a string. When setting this property programmatically, it updates the field's display value. When reading it, you get the user's current input. The value should be a numeric string (decimal or integer).

Anchor to inputMode
inputMode
"decimal" | "numeric"
Default: 'decimal'
required

The type of virtual keyboard to display on mobile devices.

  • decimal: Shows a numeric keyboard with a decimal point, suitable for prices or measurements.
  • numeric: Shows a numeric keyboard without a decimal point, suitable for whole numbers like quantities.

Learn more about the inputmode attribute.

number
Default: 1
required

The amount the value can increase or decrease by. This can be an integer or decimal. If a max or min is specified with step when increasing/decreasing the value via the buttons, the final value will always round to the max or min rather than the closest valid amount.

number
Default: Infinity
required

The highest decimal or integer value accepted for the field. When used with step, the value rounds down to the maximum number.

Users can still type values higher than the maximum using the keyboard. Implement validation to enforce this constraint.

number
Default: -Infinity
required

The lowest decimal or integer value accepted for the field. When used with step, the value rounds up to the minimum number.

Users can still type values lower than the minimum using the keyboard. Implement validation to enforce this constraint.

Anchor to prefix
prefix
string
Default: ''
required

A non-editable text value displayed immediately before the editable portion of the field. This is useful for displaying an implied part of the value, such as https:// or +353.

This text can't be edited by the user and is not included in the field's value. The prefix might not appear until the user interacts with the field. For example, an inline label might occupy the prefix position until the user focuses the field.

Anchor to suffix
suffix
string
Default: ''
required

A non-editable text value displayed immediately after the editable portion of the field. This is useful for displaying an implied part of the value, such as @shopify.com or %.

This text can't be edited by the user and is not included in the field's value. The suffix might not appear until the user interacts with the field. For example, an inline label might occupy the suffix position until the user focuses the field.

Anchor to autocomplete
autocomplete
"on" | "off" | | `section-${string} one-time-code` | `section-${string} cc-number` | `section-${string} cc-csc` | "shipping one-time-code" | "shipping cc-number" | "shipping cc-csc" | "billing one-time-code" | "billing cc-number" | "billing cc-csc" | `section-${string} shipping one-time-code` | `section-${string} shipping cc-number` | `section-${string} shipping cc-csc` | `section-${string} billing one-time-code` | `section-${string} billing cc-number` | `section-${string} billing cc-csc`
Default: 'on' for everything else
required

Controls browser autofill behavior for the field.

Basic values:

  • on - Enables autofill without specifying content type (default)
  • off - Disables autofill for sensitive data or one-time codes

Specific field values describe the expected data type. You can optionally prefix these with:

  • section-${string} - Scopes autofill to a specific form section (when multiple forms exist on the same page)
  • shipping or billing - Indicates whether the data is for shipping or billing purposes
  • Both section and group (for example, section-primary shipping email)

Providing a specific autofill token helps browsers suggest more relevant saved data.

Learn more about the set of autocomplete values supported in browsers.

Anchor to defaultValue
defaultValue
string
required

The initial value of the field when it first loads. Unlike placeholder, this is a real value that the user can edit and that gets submitted with the form. Once the user starts typing, their input replaces it. Changing this property after the field has loaded has no effect. To update the field value at any time, use value instead.

Anchor to details
details
string
required

Supplementary text displayed below the checkbox to provide additional context, instructions, or help. Use this to explain what checking the box means or provide guidance to users. This text is announced to screen readers.

Anchor to error
error
string
required

An error message displayed below the checkbox to indicate validation problems. When set, the checkbox is styled with error indicators and the message is announced to screen readers.

Anchor to label
label
string
required

The text displayed as the field label, which identifies the purpose of the field to users. This label is associated with the field for accessibility and helps users understand what information to provide.

Anchor to labelAccessibilityVisibility
labelAccessibilityVisibility
"visible" | "exclusive"
Default: 'visible'
required

Controls whether the label is visible to all users or only to screen readers.

  • visible: The label is shown to everyone (default).
  • exclusive: The label is visually hidden but still announced by screen readers.

Use exclusive when the surrounding context makes the label redundant visually, but screen reader users still need it for clarity.

Anchor to placeholder
placeholder
string
required

The placeholder text displayed in the field when it's empty, providing a hint about the expected input format or value.

Anchor to readOnly
readOnly
boolean
Default: false
required

Whether the field is read-only and can't be edited. Read-only fields remain focusable and their content is announced by screen readers.

Anchor to required
required
boolean
Default: false
required

Whether the field requires a value before form submission. Displays a visual indicator and adds semantic meaning, but doesn't automatically validate or show errors. Use the error property to display validation messages.

Anchor to disabled
disabled
boolean
Default: false
required

Whether the field is disabled, preventing any user interaction.

string
required

A unique identifier for the element. Use this to reference the element in JavaScript, link labels to form controls, or target specific elements for styling or scripting.

string
required

The name attribute for the field, used to identify the field's value when the form is submitted. Must be unique within the nearest containing form.

The number field component provides event callbacks for handling user interactions. Learn more about handling events.

<'input'>
required

A callback fired when the number field loses focus.

Learn more about the blur event.

Anchor to change
change
<'input'>
required

A callback fired when the number field value changes.

Learn more about the change event.

Anchor to focus
focus
<'input'>
required

A callback fired when the number field receives focus.

Learn more about the focus event.

Anchor to input
input
<'input'>
required

A callback fired when the user inputs data into the number field.

Learn more about the input event.


Anchor to Add a basic number fieldAdd a basic number field

Collect a numeric value from merchants with step controls and a defined range. This example shows a number field with a label, placeholder, step increment, and min/max bounds.

Preview

html

<s-number-field
label="Quantity"
details="Number of items in stock"
placeholder="0"
step="5"
min="0"
max="100"
></s-number-field>

Anchor to Add a prefix and suffix for currency inputAdd a prefix and suffix for currency input

Add a prefix and suffix to provide context for the expected value, such as a currency symbol or unit. This example shows a price field with a dollar sign prefix, currency suffix, and decimal input mode.

Preview

html

<s-number-field
label="Product price"
value="29.99"
prefix="$"
suffix="CAD"
inputMode="decimal"
step="0.01"
min="0"
></s-number-field>

Anchor to Show a validation errorShow a validation error

Display an error message when a value is outside the accepted range or a required field is empty. This example shows a required number field with an error indicating the minimum allowed value.

Preview

html

<s-number-field
label="Order quantity"
value="0"
min="1"
max="999"
step="1"
required
error="Quantity must be at least 1"
></s-number-field>

Anchor to Disable or make a number field read-onlyDisable or make a number field read-only

Prevent editing by making a number field read-only or fully disabled. This example shows a read-only price field and a disabled tax rate field, both with pre-filled values.

Preview

html

<s-stack gap="base">
<s-number-field
label="Base price"
value="49.99"
prefix="$"
readOnly
></s-number-field>

<s-number-field
label="Tax rate"
value="13"
suffix="%"
disabled
></s-number-field>
</s-stack>

  • Use for numeric-only input: Choose the component when you need strictly numeric values like quantities, measurements, or percentages. For values that might contain letters or symbols (like product codes or phone numbers), use text field instead.
  • Provide context with units: Display units of measurement using prefix or suffix to clarify what the number represents. Without context, merchants might not know if they're entering dollars, kilograms, or percentages.
  • Set realistic constraints: Define minimum and maximum values that reflect actual business rules. This guides merchants toward valid inputs and prevents unrealistic values before form submission.
  • Validate and provide clear feedback: Always validate numeric input and show specific error messages that explain what went wrong and how to fix it. Generic error messages don't help merchants understand what value to enter.

  • Setting inputMode suggests a keyboard layout on mobile but doesn't prevent merchants from entering non-numeric characters. Always validate input values in your change event handler.

Was this page helpful?