Skip to main content
U.S. flag

An official website of the United States government

Dot gov

The .gov means it’s official.
Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.


The site is secure.
The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.


Number input

Use: Deployed English, Spanish, Tagalog
Number input elements are used for numeric inputs.

Number input

  • Number input always has the type of number and provides a min and max attribute to set a range on the component.

View va-number-input in Storybook


When to use number input

  • When a number should be the only accepted value within an input element.
  • If you can’t reasonably predict a user’s answer to a prompt and there might be wide variability in users’ answers.
  • When users want to be able to paste in a response.

When to consider something else

  • When users are choosing from a specific set of options.
  • A number is not the only accepted value for the input.
  • The number should be a type other than number, ie: telephone numbers

How to use

  • Only show error validation messages or stylings after a user has interacted with a particular field.
  • Avoid using placeholder text that appears within a input field before a user starts typing. If placeholder text is no longer visible after a user clicks into the field, users will no longer have that text available when they need to review their entries. (People who have cognitive or visual disabilities have additional problems with placeholder text.)

Native Events

  • Native onInput and onBlur events are available on this component. They can be used by adding the event handler to your component and it will then listen to the event and respond accordingly when the event fires.

Code usage

Attributes and Properties

Property Attribute Type Default Description
enableAnalytics enable-analytics boolean false Emit component-library-analytics events on the blur event.
error error string The error message to render.
hint hint string Optional hint text.
inputmode inputmode "decimal" | "numeric" The inputmode attribute.
label label string The label for the text input.
max max number | string Maximum number value The max attribute specifies the maximum value for an input element.
min min number | string Minimum number value The min attribute specifies the minimum value for an input element.
name name string The name to pass to the input element.
required required boolean false Set the input to required and render the (Required) text.
value value string The value for the input.


Name Description
component-library-analytics The event used to track usage of the component. This is emitted when the input is blurred and enableAnalytics is true.

Accessibility considerations

  • Avoid placeholder text for accessibility reasons. Most browsers’ default rendering of placeholder text does not provide a high enough contrast ratio.
  • Avoid breaking numbers with distinct sections (such as phone numbers, Social Security Numbers, or credit card numbers) into separate input fields. For example, use one input for phone number, not three (one for area code, one for local code, and one for number). Each field needs to be labeled for a screen reader and the labels for fields broken into segments are often not meaningful.
Edit this page in GitHub (Permissions required)
Last updated: May 23, 2022