日本語

Hide Number Input Spin Buttons with CSS

​​CSS​Forms,HTML,JavaScript

The up and down arrows on the right edge of <input type="number"> are called spin buttons. You can hide them by adding -webkit-appearance: none to the ::-webkit-inner-spin-button pseudo-element. Use this when a field takes a number such as a quantity or an amount and you don't want to show the arrows. The appearance: textfield example on MDN's appearance page did not work in the Chromium I tested. Hiding the buttons does not stop the value from changing with the ↑ and ↓ keys or the mouse wheel, so I also checked that behavior and how to stop it.

Note

The test environment was Ubuntu 24.04, Node.js 22.23.4, Playwright 1.63.0, and Chromium 153. I ran Chromium with Playwright to check the pixels and the key behavior. I did not test Firefox, Safari, or how things look and behave on smartphones. The browser versions listed for each feature are the values from the compatibility data (@mdn/browser-compat-data 8.1.8).

Three number inputs stacked vertically, each with the cursor over it. The first has no CSS and shows up and down arrow buttons on its right edge. The second has appearance: textfield set on the input and still shows the arrow buttons. The third has -webkit-appearance: none set on the pseudo-element and shows nothing on its right edge. The labels in the image are in Japanese; the top, middle, and bottom rows correspond to nothing added, appearance: textfield, and -webkit-appearance: none on the pseudo-element.
The cursor is over each input. From top: nothing added, appearance: textfield, and -webkit-appearance: none on the pseudo-element (the labels in the image are in Japanese)

Add -webkit-appearance: none to the pseudo-elements

The CSS that hides the spin buttons is:

css
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

In Chromium in the test environment, the spin buttons are not drawn normally. They appear only when the cursor is over the field or the field has focus. I counted the non-white pixels in the 18px band at the right edge of the input. With nothing added, there were 40 such pixels with the cursor over the field and 42 with focus. With the CSS above, there were 0 pixels with the cursor over the field. With focus, there were 2, both gray pixels at the top-right and bottom-right corners of the counted area. The spin buttons were not drawn.

According to MDN's page on ::-webkit-inner-spin-button, this pseudo-element is not part of any standard, and it works only in browsers based on WebKit and Blink. The compatibility data lists support from Chrome 6, Edge 79, and Safari 5 (4.2 on iOS). Firefox does not support it.

The CSS above lists two pseudo-elements. In the Chromium I tested, ::-webkit-inner-spin-button was the one that worked. Using only that one hid the spin buttons, but using only ::-webkit-outer-spin-button did not. The compatibility data has no entry for ::-webkit-outer-spin-button.

Writing appearance: none without the -webkit- prefix, or display: none, on the same pseudo-element also hid the spin buttons. With the cursor over the field, the screenshots for display: none and -webkit-appearance: none did not differ by a single pixel. Some people also add margin: 0 to this CSS. In the test environment, adding it or leaving it out did not change how the field looked with the cursor over it.

In Chromium, appearance: textfield does not hide the buttons

MDN's appearance page has an example that sets appearance: textfield on a number input, and it says that some browsers hide the spin buttons with it.

In Chromium 153 in the test environment, setting appearance: textfield on input gave a computed value of textfield. The spin buttons still appeared when the cursor was over the field (the second row in the image above). The number of non-white pixels at the right edge was 40, the same as with nothing added. Using -webkit-appearance: textfield, or appearance: none on the input itself, also left the buttons visible. To hide them in Chromium, set the rule on the pseudo-element, not on input.

Hiding the buttons does not stop the keys and wheel from changing the value

Even with the spin buttons hidden, the field is still a number input. The ↑ and ↓ keys still change the value.

A number input with the spin buttons hidden. The cursor is moved to the right edge, and no buttons appear. After a click, the "Click" label in the top-left turns into a pink background, and a pink ring appears at the cursor. Then the ↑ key is pressed three times. Each press highlights the key-count label in the top-left (press 1 of 3, then 2 of 3, then 3 of 3) and the key graphic on the screen in pink. The value in the field and the number next to the "Value" label on the right go up in pink from 5 to 6, 7, and 8. The labels in the image are in Japanese.
The cursor is over an input with the spin buttons hidden, and the ↑ key is pressed three times. Each press raises the value by 1. The labels in the image are in Japanese.

In the test environment, I used an input with min="0" max="10" step="1" and a value of 5. I compared an input with nothing added against one with the spin buttons hidden. In the input with nothing added, clicking the upper half of the right edge changed the value to 6. In the input with the buttons hidden, clicking the same spot left the value at 5. The key behavior was the same in both. Pressing ↑ changed the value to 6. Then pressing ↓ twice changed it to 4. Pressing ↑ ten more times stopped at 10, which is the max. In both inputs, the role in the accessibility tree was still spinbutton. MDN's appearance page also says that the appearance property does not affect functionality, and that the value can still be changed with the up and down cursor keys.

The mouse wheel also changes the value. When the input with the buttons hidden had focus, scrolling the wheel down over it changed the value from 5 to 4, and the page did not scroll. Without focus, the value did not change, and the page scrolled.

To stop the wheel from changing the value, cancel the default action of the wheel event:

js
const input = document.querySelector('input[type="number"]');

input.addEventListener(
  'wheel',
  (e) => {
    if (document.activeElement === input) {
      e.preventDefault();
    }
  },
  { passive: false },
);

In the test environment, scrolling the wheel while the field had focus left the value at 5. The page did not scroll, and the field kept its focus. Without focus, the code does nothing, so the page scrolled 100px, the same as before the code was added.

If you want the page to scroll, you can instead remove focus when the wheel moves, for example with input.addEventListener('wheel', () => input.blur());, rather than calling preventDefault(). In the test environment, the value stayed at 5, the page scrolled 100px, and the field lost focus.

If you don't need the spin buttons, use type="text" with inputmode="numeric"

The "Accessibility considerations" section of MDN's page on input type="number" recommends not using type="number" when the spin buttons are not an essential feature. It suggests using inputmode="numeric" and the pattern attribute instead. The same section also gives as a reason that with type="number", a user trying to do something else may accidentally increase the value.

html
<input type="text" inputmode="numeric" pattern="[0-9]*">

In the test environment, this input showed no spin buttons when the cursor was over it, even without any CSS. Pressing ↑ did not change the value, which stayed at 5. The role in the accessibility tree is textbox.

You can check whether the input contains a non-digit character with pattern. When "12a" was entered, validity.patternMismatch was true. When "12" was entered, validity.valid was true. If you need the value as a number, convert it yourself. When "12" was entered, valueAsNumber was 12 for type="number" and NaN for type="text".

​Posted by 86