advanced forms

Tailwind CSS Input Number

The Input Number, also called Quantity Selector, lets users specify quantities easily. Ideal for selecting product amounts or seat numbers, it offers simple increment and decrement controls, making numeric input smooth for e-commerce and more.

Class Name
Type
Description
inputComponentBasic input field.
input-groupComponentAdds inline addons to inputs.
input-number-disabled:{tw-utility-class}ModifierThe modifier allows setting Tailwind classes when input’s value is set to zero.
is-validModifierAdds success style to the input.
is-invalidModifierAdds error style to the input.

Basic example of input number.

Enclose the data-input-number-input and data-input-number-decrement elements of the input-number within data-input-number-increment within data-input-number.

Input number with label.

Success state can be show using is-valid class.

Error state can be show using is-invalid class.

Basic disabled state.

Vertically stacked buttons example.

Horizontally stacked buttons example.

Horizontally stretched buttons example.

Here’s a simple example: demonstrate setting a maximum width for the main container.

Here’s an example of a movie ticket booking number counter.

Increase or decrease values in steps. This example uses a ":step" value of 5.

You can control the minimum value with ":min" and set the maximum value with ":max".

In the example below, the maximum number that can be selected is 15.

In the example below, the minimum number that can be selected is -15.

PARAMETERS
DESCRIPTION
OPTIONS
DEFAULT VALUE
data-input-numberActivate an Input Number by specifying on an element.--
data-input-number-inputApplied to the input element.--
data-input-number-incrementApplied to the increment button.--
data-input-number-decrementApplied to the decrement button.--
:stepDetermines the step by which the value will increase or decrease.number1
:minDefines the minimum value that can be entered. Setting it to -Infinity allows unrestricted negative values.number /
“-Infinity”
0
:maxmax Defines the maximum possible value.number / nullnull

The HSInputNumber object is contained within the global window object.

METHOD
DESCRIPTION
HSInputNumber.getInstance(target, isInstance)
Returns the element associated to the target.
  • target should be a Node or string (valid selector).
  • isInstance boolean. Returns the instance instead of Node if true.
METHOD
DESCRIPTION
RETURNING VALUE
on:changeCalled when input value is changed.Current value.

Assign an ID to the data-input-number in the events. Increment the number and check the output in the console.

Open any accordion event example.

const el = HSInputNumber.getInstance('#input-number');

el.on('change', ({inputValue}) => {console.log('Changed to:', inputValue)});