How to remove Input buttons type="number"

5

How to remove the two buttons of Input type="number" in HTML5? Example:

<p>Quero que isso:</p>
<input type="number">

<p>Vire isso porém sem usar o text, pois preciso do comportamento do number:</p>
<input type="text">
    
asked by anonymous 04.08.2017 / 15:55

1 answer

10

Locking by css.

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;
}
<input type="number" onkeypress='return event.charCode >= 48 && event.charCode <= 57'></input>

Or you could do a text and validate by just accepting numbers. As below:

<input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57'>
</input>
    
04.08.2017 / 15:58