Enabling Fractions/Cents/Decimals for Number Input

To allow fractions on an number input, you need to specify the step attribute to any:

<input type="number" min="1" step="any" />
Run code snippetEdit code snippet Hide Results Copy to answer Expand

This will specifically keep Chrome from displaying an error when a decimal/fractional currency is entered into the input. Mozilla, IE, etc... don't error out if you forget to specify step="any". W3C spec states that step="any" should, indeed, be needed to allow for decimals. So, you should definitely use it. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#step

Note that if you want the up/down buttons to do a specific granularity, then you must specify a numeric step such as ".01".

Also, the number input is now pretty widely supported (>90% of users).


What Input Options are there for Money/Currency?

The title of the question has since changed and takes on a slightly different meaning. One could use both number or text input in order to accept money/decimals.

For an input field for currency/money, it is recommended to use input type of number and specify appropriate attributes as outlined above. As of 2020, there is not a W3C spec for an actual input type of currency or money.

Main reason being it automatically coerces the users into entering a valid standard currency format and disallows any alphanumeric text. With that said, you could certainly use the regular text input and do some post processing to only grab the numeric/decimal value (there should be server side validation on this at some point as well).

The OP detailed a requirement of currency symbols and commas. If you want fancier logic/formatting like that, (as of 2020) you'll need to create custom JS logic for a text input or find a plugin.

Answer from karns on Stack Overflow
Top answer
1 of 7
113

Enabling Fractions/Cents/Decimals for Number Input

To allow fractions on an number input, you need to specify the step attribute to any:

<input type="number" min="1" step="any" />
Run code snippetEdit code snippet Hide Results Copy to answer Expand

This will specifically keep Chrome from displaying an error when a decimal/fractional currency is entered into the input. Mozilla, IE, etc... don't error out if you forget to specify step="any". W3C spec states that step="any" should, indeed, be needed to allow for decimals. So, you should definitely use it. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#step

Note that if you want the up/down buttons to do a specific granularity, then you must specify a numeric step such as ".01".

Also, the number input is now pretty widely supported (>90% of users).


What Input Options are there for Money/Currency?

The title of the question has since changed and takes on a slightly different meaning. One could use both number or text input in order to accept money/decimals.

For an input field for currency/money, it is recommended to use input type of number and specify appropriate attributes as outlined above. As of 2020, there is not a W3C spec for an actual input type of currency or money.

Main reason being it automatically coerces the users into entering a valid standard currency format and disallows any alphanumeric text. With that said, you could certainly use the regular text input and do some post processing to only grab the numeric/decimal value (there should be server side validation on this at some point as well).

The OP detailed a requirement of currency symbols and commas. If you want fancier logic/formatting like that, (as of 2020) you'll need to create custom JS logic for a text input or find a plugin.

2 of 7
87

Try using step="0.01", then it will step by a penny each time.

eg:

<input type="number" min="0.00" max="10000.00" step="0.01" />
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Top answer
1 of 7
98

Add step="0.01" to the <input type="number" /> parameters:

<input type="number" min="0.01" step="0.01" max="2500" value="25.67" />

Demo: http://jsfiddle.net/uzbjve2u/

But the Dollar sign must stay outside the textbox... every non-numeric or separator charachter will be cropped automatically.

Otherwise you could use a classic textbox, like described here.

2 of 7
28

In the end I made a jQuery plugin that will format the <input type="number" /> appropriately for me. I also noticed on some mobile devices the min and max attributes don't actually prevent you from entering lower or higher numbers than specified, so the plugin will account for that too. Below is the code and an example:

(function($) {
  $.fn.currencyInput = function() {
    this.each(function() {
      var wrapper = $("<div class='currency-input' />");
      $(this).wrap(wrapper);
      $(this).before("<span class='currency-symbol'>$</span>");
      $(this).change(function() {
        var min = parseFloat($(this).attr("min"));
        var max = parseFloat($(this).attr("max"));
        var value = this.valueAsNumber;
        if(value < min)
          value = min;
        else if(value > max)
          value = max;
        $(this).val(value.toFixed(2)); 
      });
    });
  };
})(jQuery);

$(document).ready(function() {
  $('input.currency').currencyInput();
});
.currency {
  padding-left:12px;
}

.currency-symbol {
  position:absolute;
  padding: 2px 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input type="number" class="currency" min="0.01" max="2500.00" value="25.00" />
Run code snippetEdit code snippet Hide Results Copy to answer Expand

🌐
CodePen
codepen.io › 559wade › pen › LRzEjj
Currency Format Input Field
Minimize HTML Editor · Fold All ...00,000.00"> <button type="submit">Submit</button> </form> <p>Auto format currency input field with commas and decimals if needed....
Author: konstantin-lukas
🌐
JSFiddle
jsfiddle.net › trixta › using type number for a currency input
Using type number for a currency input - JSFiddle - React, Tailwind, and code Playground
July 3, 2014 - <script src="http://afarkas.github.io/webshim/js-webshim/minified/polyfiller.js"></script> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> <form action="#"> <div> <h2>With spinbuttons</h2> <div class="form-row"> <label for="c1">Currency</label> <input type="number" value="1000" min="0" step="0.01" data-number-to-fixed="2" data-number-stepfactor="100" class="currency" id="c1" /> </div> <div class="form-row"> <label for="c2">Currency w bootstrap</label> <div class="input-group"> <span class="input-group-addon">$</span> <input type="number" value="10
Published: Jul 03, 2014
Author: trixta
🌐
FormKit
formkit.com › inputs › currency input
Currency Input ⚡️ FormKit
<FormKit type="currency" name="currency" min={-10} max={1000} step={0.0001} currency="USD" displayLocale="en-US" decimals={4} minDecimals={2} defaultValue={123.1234}/> ... You can target a specific section of an input using that section's "key", ...
Find elsewhere
🌐
Quora
quora.com › Is-there-any-unique-input-type-for-accepting-currency-values-in-HTML-If-yes-what-is-the-syntax-of-the-HTML-to-receive-inputs-for-currency-values
Is there any unique input type for accepting currency values in HTML? If yes, what is the syntax of the HTML to receive inputs for currency values? - Quora
Answer (1 of 12): There is no “unique” input type for accepting currency values in HTML. That means, the type attribute of the input tag doesnt have such a value that corresponds to some currency related stuff. You can do JavaScript for trying to validate currency related stuff, or use ...
🌐
JSFiddle
jsfiddle.net › NfMQ7 › 178
HTML5 Input for Currency Format - JSFiddle - Code Playground
My current favorites are Input and Commit Mono. Our CSS Flexbox generator lets you create a layout, and skip knowing the confusing properties and value names (let's be honest the W3C did not make a good job here). Not gonna lie, this was heavily inspired by flexer.dev but coded completely from scratch. Adding External Resources will no longer create a list of resources in the sidebar but will be injected as a LINK or SCRIPT tag inside of the HTML panel.
🌐
Delft Stack
delftstack.com › home › howto › html › html currency input
How to Create the Currency Input in HTML | Delft Stack
February 2, 2024 - In HTML, a normal <input> element is available, and we can set its type according to our requirements. We cannot make the type a currency input by just setting the type to number; we need to make more changes using either JavaScript or jQuery.
🌐
DEV Community
dev.to › techworld_with_nana › input-field-type-currency-problem-solved-3gf1
Input field type "Currency" problem solved 💲💡 - DEV Community
January 25, 2020 - We use the <input type=number” /> when input field is in focus and save the value in state as a number to use it in calculations. When the input field loses focus (onBlur callback), we switch the Input field to <input type=“text” /> to ...
🌐
GitConnected
levelup.gitconnected.com › creating-a-localized-currency-input-in-react-without-libraries-or-bugs-2f186124aedc
Creating a Localized Currency Input in React without Libraries (or bugs) | by Jonatan Kruszewski | Level Up Coding
May 21, 2024 - The HTML input doesn’t support type: currency. That creates a problem: implementing a visually pleasant component that handles currency is, at the very least, a challenge. You need to support different separators for decimals and thousands. If you thought it wasn’t a complicated task so far, let me introduce you to Bulgarian.
🌐
Cyber Bot Machines
cyberbotmachines.com › home › blog › html currency input
HTML Currency Input - Cyber Bot Machines
April 10, 2022 - type=”number” This specifies that you can only input numbers and also on mobile devices it gives you numeric keyboard.
🌐
Justice
design-patterns.service.justice.gov.uk › archive › currency-input
Currency input - MOJ Design System
Open this example (Currency input (example)) in a new window · HTML (Currency input (example)) Nunjucks (Currency input (example)) <div class="govuk-form-group"> <label class="govuk-label govuk-!-font-weight-bold" for="amount-1"> Amount </label> <div id="amount-1-hint" class="govuk-hint"> Enter the amount you want to exchange </div> <span class="moj-label__currency">&pound;</span> <input class="govuk-input moj-input__currency govuk-input--width-10" id="amount-1" name="amount" type="text" aria-describedby="amount-1-hint" autocomplete="off" pattern="[0-9]*"> </div> Nunjucks macro options ·
🌐
npm
npmjs.com › package › react-currency-input-field
react-currency-input-field - npm
July 14, 2026 - import CurrencyInput from 'react-currency-input-field'; // US Dollar <CurrencyInput intlConfig={{ locale: 'en-US', currency: 'USD' }} /> // British Pound <CurrencyInput intlConfig={{ locale: 'en-GB', currency: 'GBP' }} /> // Canadian Dollar ...
      » npm install react-currency-input-field
    
Published: Jul 14, 2026
Version: 4.0.6
🌐
GitHub
gist.github.com › siresorose › d5f349838a5c82d7faa4b13f046af668
Currency Format Input Field · GitHub
Auto format currency input field with commas and decimals if needed. This is how I would personally expect one to work. Works left to right without forcing user to enter 00 cents if there is none. Text is automatically formatted with commas and cursor is placed back where user left off after formatting vs cursor moving to the end of the input.
🌐
Laserfiche Answers
answers.laserfiche.com › questions › 207791 › How-do-i-format-HTML-currency-values-or-the-value-of-a-form-field
How do i format HTML currency values or the value of a form field? - Laserfiche Answers
April 6, 2023 - I would add a hidden text field that I fill with the formatted currency amount and then use the hidden text field to populate the html. $('.ShownCurrency input').on('change', function () { var txtCurrency = $('.ShownCurrency input').val() $('.hiddenCurrencyToText input').val('$'.concat(txtCurrency)); }); 1 0 ·
🌐
MDBootstrap
mdbootstrap.com › standard › material design for bootstrap 5 & vanilla javascript
Currency Format in Input Form - Material Design for Bootstrap
<p>I have input form with type=number. When the user enters the number, I'd like it formatted to a currency (specifically, US dollars). How can I do this?</p> <pre class=prettyprint><code>&lt;div class=form-outline&gt; &lt;input type=number id=typeNumber class=form-con