Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I hide the HTML5 number input’s spin box?

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"> 
like image 921
Alan Avatar asked Sep 24 '10 20:09

Alan


People also ask

How do you hide input type number arrows?

Using inputmode=”numeric” attribute you can find an input box without an arrow.

How do I turn off input type number?

If you are able/allowed to use jQuery, you can disable keypress on the type='number' . $("[type='number']"). keypress(function (evt) { evt. preventDefault(); });

How do you hide the input field in HTML?

The <input type="hidden"> defines a hidden input field. A hidden field let web developers include data that cannot be seen or modified by users when a form is submitted.


1 Answers

This CSS effectively hides the spin-button for webkit browsers (have tested it in Chrome 7.0.517.44 and Safari Version 5.0.2 (6533.18.5)):

input::-webkit-outer-spin-button,  input::-webkit-inner-spin-button {      /* display: none; <- Crashes Chrome on hover */      -webkit-appearance: none;      margin: 0; /* <-- Apparently some margin are still there even though it's hidden */  }    input[type=number] {      -moz-appearance:textfield; /* Firefox */  }
<input type="number" step="0.01" />

You can always use the inspector (webkit, possibly Firebug for Firefox) to look for matched CSS properties for the elements you are interested in, look for Pseudo elements. This image shows results for an input element type="number":

Inspector for input type=number (Chrome)

like image 176
antonj Avatar answered Sep 21 '22 18:09

antonj