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
🌐
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.gi... 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"> ...
Published: Jul 03, 2014
Author: trixta
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

🌐
CodePen
codepen.io › 559wade › pen › LRzEjj
Currency Format Input Field
Minimize HTML Editor · Fold All ... Amount</label> <input type="text" name="currency-field" id="currency-field" pattern="^\$\d{1,3}(,\d{3})*(\.\d+)?$" value="" data-type="currency" placeholder="$1,000,000.00"> <button ...
🌐
GitHub
github.com › konstantin-lukas › intl-currency-input
GitHub - konstantin-lukas/intl-currency-input: This library allows you to have currency inputs with custom formatting in your HTML forms! · GitHub
The first parameter is the HTMLInputElement to mount to. This input element should be of type="text". The second parameter determines the default value. This value should follow the following format: ^-?(0|[1-9]\d*)(\.\d+)?$. The amount of decimal places this initial value has implicitly determines how many decimal places will be shown in the input field.
Author: konstantin-lukas
🌐
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 ·
🌐
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 ...
🌐
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.
Find elsewhere
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

🌐
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. For example, we can create the <input> field in HTML like below; it contains some attributes.
🌐
npm
npmjs.com › package › react-currency-input-field
react-currency-input-field - npm
July 14, 2026 - import CurrencyInput from 'react-currency-input-field'; <CurrencyInput id="input-example" name="input-name" placeholder="Please enter a number" defaultValue={1000} decimalsLimit={2} onValueChange={(value, name, values) => console.log(value, ...
      » 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.
🌐
WICG
discourse.wicg.io › t › proposal-input-type-currency › 5398
[Proposal] input[type=currency]
Today, these web applications relies on third party js libraries that can make a regular input behave like a monetary field (thousand and fraction separators, currency symbols etc). To make opportunity for a more consistent user experience and easier development work for web developers, I want to propose an new input type, the currency input type. Example how it should render below:
🌐
MDBootstrap
mdbootstrap.com › standard › material design for bootstrap 5 & vanilla javascript
Currency Format in Input Form - Material Design for Bootstrap
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
🌐
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", ...
🌐
Aguidehub
aguidehub.com › blog › bootstrap-input-currency-format-example
Bootstrap input currency format example
June 28, 2022 - Example of make bold part of text of mui typography in React js with step by step tutorial - aGuideHub ... In this article, we will discuss the top 50 HTML Interview Questions you should absolutely know to crack those trying interviews and land your dream job.
🌐
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 ...
🌐
CodeFronts
codefronts.com › home › ui components › 28 css input fields › currency input
Currency Input — Free CSS Code & Live Demo | CodeFronts
May 4, 2026 - Demo: Currency Input Source: https://codefronts.com/components/css-input-fields/currency-input/ Right-aligned numeric input with an inline `$` prefix. `inputmode="decimal"` brings up the right mobile keyboard; `:focus-within` lights the prefix to match the field accent. ## HTML ```html <label class="if-16"> <span class="if-16-label">Amount</span> <span class="if-16-wrap"> <span class="if-16-prefix">$</span> <input type="text" name="amount" inputmode="decimal" pattern="[0-9.,]*" placeholder="0.00" /> <span class="if-16-suffix">USD</span> </span> </label> ``` ## CSS ```css .if-16 { display: grid
Published: May 04, 2026
🌐
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.