Using the input element to obtain a number

The type="number" creates an input box that will only accept numeric values.

The following table describes the additional attributes that are available when using type="number".

AttributeDescriptionNew in HTML5
listSpecifies the id of a datalist element that provides values for this element.Yes
minSpecifies the minimum acceptable value for input validation.Yes
maxSpecifies the maximum acceptable value for input validationYes
readonlymakes the input box read-onlyNo
requiredSpecifies the required fieldYes
stepSpecifies the granularity of increments and decrements to the value.Yes
valueSpecifies the initial value for the element.No

The values for the min, max, step, and value attributes can be expressed as integer or decimal numbers.

 
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<body>
      <form method="post" action="http://yourServer/form">
            <p>
                  <label for="name"> Name: <input value="Mark" id="name"
                        name="name" />
                  </label>
            </p>
            <p>
                  <label for="password"> Password: <input type="password"
                        placeholder="Min 6 characters" id="password" name="password" />
                  </label>
            </p>
            <p>
                  <label for="fave"> Input: <input value="CSS" id="fave" name="fave" />
                  </label>
            </p>
            <p>
                  <label for="price"> $ per unit in your area: <input
                        type="number" step="1" min="0" max="100" value="1" id="price"
                        name="price" />
                  </label>
            </p>
            <input type="submit" value="Submit Vote" />
      </form>
</body>
</html>
  
Click to view this demo.
Home 
  HTML CSS Book 
    HTML  

input Restricted:
  1. Using the input Element to Restrict Data Entry
  2. Using the input element to obtain a number
  3. Using input Element to Obtain a Number in a Given Range
  4. Using the input Element to Obtain a Boolean Response
  5. Using the input Element to Create Fixed Choices
  6. Using the input Element to Obtain email address
  7. Using the input element to obtain telephone number
  8. Using the input Element to Obtain url
  9. Using the input element to obtain times and dates
  10. Using the input Element to Obtain a Color
  11. Using the input Element to Obtain Search Terms
  12. Using the input element to create hidden data items
  13. Using the input Element to Create Image Buttons and Maps
  14. Using the input element to upload files
Related: