Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize spin box arrows

Tags:

html

css

I want to know how to customize the arrows of a spin box.

input[type="number"]::-webkit-inner-spin-button, 
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: inner-spin-button !important;
    opacity: 1 !important;
}
<input type="number" />

This is what I want to get.

This is what I want to get.

Where should I start?? (Do I have to use jQuery widget or javascript to customize it?)

like image 981
Kid Avatar asked Oct 17 '25 13:10

Kid


2 Answers

Screenshot (Chrome, macOS):

enter image description here

Code:

input[type="number"] {
  height: 32px;
  border-radius: 4px;
  border: 1px solid #d8d8d8;
  position: relative;
  text-align: center;
  font-size: 20px;
  width: 80px;
  outline: none;
  background-image: url('data:image/svg+xml;utf8,%3Csvg%20version%3D%221.1%22%20viewBox%3D%220%200%2050%2067%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cg%20fill%3D%22none%22%20stroke-width%3D%222%22%3E%3Cline%20x1%3D%221%22%20x2%3D%2250%22%20y1%3D%2233.5%22%20y2%3D%2233.5%22%20stroke%3D%22%23D8D8D8%22%2F%3E%3Cpolyline%20transform%3D%22translate(25%2020)%20rotate(45)%20translate(-25%20-20)%22%20points%3D%2219%2026%2019%2014%2032%2014%22%20stroke%3D%22%23000%22%2F%3E%3Cpolyline%20transform%3D%22translate(25%2045)%20rotate(225)%20translate(-25%20-45)%22%20points%3D%2219%2052%2019%2039%2032%2039%22%20stroke%3D%22%23000%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E');
  background-position: center right;
  background-size: contain;
  background-repeat: no-repeat;
  caret-color: transparent;
}

input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
  opacity: 1 !important;
  background: transparent !important;
  border-width: 0px;
  margin: 0;
  border-left: 1px solid #d8d8d8;
  height: 34px;
  width: 23px;
  cursor: pointer;
}
<input type="number" value="1" />

So, it can be done. But customizations like this are usually very brittle (even if you add in the necessary cross-browser properties, which I haven't done; this only works in webkit), and can hurt usability. You're probably better off using the platform's native controls.

like image 160
Ollin Boer Bohan Avatar answered Oct 21 '25 01:10

Ollin Boer Bohan


My answer try of fix your problem with css pure, for example with input[type=number] {} you can put all of rules to change the look of the input

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: inner-spin-button !important;
  opacity: 1 !important;
  width: 50px;
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  background-color: blue !important;
  border: 2.5px solid red !important;
}

input[type=number] {
  position: relative;
  padding: 5px;
  width: 50px;
  padding-right: 25px;
  height: 30px;
  text-align: center;
  font-family: sans-serif;
  font-size: 2rem;
  border: 1px solid #9c9c9c !important;
  border-radius: 0.2em;
}
<input type="number" />

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!