Is there a consistent way across browsers to hide the new spin boxes that some browsers (such as Chrome) render for HTML input of type number? I am looking for a CSS or JavaScript method to prevent the up/down arrows from appearing.
<input id="test" type="number">
Only add this css to remove spinner on input of number
On Firefox for Ubuntu, just using
did the trick for me.
Adding
Would lead me to
everytime I tried. Same for the inner spin button.
Maybe change the number input with javascript to text input when you don't want a spinner;
and stop the user entering text;
then have the javascript change it back in case you do want a spinner;
it worked well for my purposes
This is more better answer i would like to suggest on mouse over and without mouse over
To make this work in Safari I found adding !important to the webkit adjustment forces the spin button to be hidden.
I am still having trouble working out a solution for Opera as well.
Short answer:
Longer answer:
To add to existing answer...
Firefox:
In current versions of Firefox, the (user agent) default value of the
-moz-appearance
property on these elements isnumber-input
. Changing that to the valuetextfield
effectively removes the spinner.In some cases, you may want the spinner to be hidden initially, and then appear on hover/focus. (This is currently the default behavior in Chrome). If so, you can use the following:
Chrome:
In current versions of Chrome, the (user agent) default value of the
-webkit-appearance
property on these elements is alreadytextfield
. In order to remove the spinner, the-webkit-appearance
property's value needs to be changed tonone
on the::-webkit-outer-spin-button
/::-webkit-inner-spin-button
pseudo classes (it is-webkit-appearance: inner-spin-button
by default).It's worth pointing out that
margin: 0
is used to remove the margin in older versions of Chrome.Currently, as of writing this, here is the default user agent styling on the 'inner-spin-button' pseudo class: