8

I am using the input type range bar in my code and would like to change the colour. I don't want to change anything else about it, I just want to change the colour from blue to something else.

I know that I can access it through css like so:

input[type=range] {
 -webkit-appearance: none;
}

But this alters the input range, I just want to change the color.

SeePlusPlus
  • 147
  • 1
  • 8

5 Answers5

4

just use accent-color css property to the input field and give any color to the field here I created 3 input range field with color red, green and blue but you can create any color range input with this. hope this answer is helpful

<!DOCTYPE html>
<html lang="en">
<head>
<style>
.sliderRed{
   accent-color:red;
   }
   
 .sliderGreen{
   accent-color: green;
   }
   
 .sliderBlue{
   accent-color:blue;
   }
   </style>
</head>
<body>
    <div className="m-auto my-4 flex justify-between ">
  <input type="range" class="sliderRed" id="myRange"/>

  <input type="range" class="sliderGreen" id="myRange"/>

  <input type="range" class="sliderBlue" id="myRange"/>
  </div>
</body>
</html>
3

As far as I understand, you can not change color of just one part and leave everything else as is. Furthermore, in different browsers parts of the slider are different (they are rendered differently, and their internals differ). enter image description here Check out this tool: https://toughengineer.github.io/demo/slider-styler
It allows to relatively easily style <input> range slider and generates cross browser CSS for you.

Here's a great article about how <input> range element works and how you can style its individual parts in different browsers:
https://css-tricks.com/sliding-nightmare-understanding-range-input/

paul
  • 448
  • 4
  • 11
0

// .chrome styling Vanilla JS

document.getElementById("myinput").oninput = function() {
  var value = (this.value-this.min)/(this.max-this.min)*100
  this.style.background = 'linear-gradient(to right, #82CFD0 0%, #82CFD0 ' + value + '%, #fff ' + value + '%, white 100%)'
};
#myinput {
  background: linear-gradient(to right, #82CFD0 0%, #82CFD0 50%, #fff 50%, #fff 100%);
  border: solid 1px #82CFD0;
  border-radius: 8px;
  height: 7px;
  width: 356px;
  outline: none;
  transition: background 450ms ease-in;
  -webkit-appearance: none;
}
<div class="chrome">
  <input id="myinput" min="0" max="60" type="range" value="30" />
</div>
0

1. use DOM .style.accentColor property

     DOM_range_element.style.accentColor = 'blue' 

2. use jquery .css()

  $('#DOM_range_element').css({'accent-color':'blue'})

or

  $('#DOM_range_element').css('accent-color', 'blue')

Here is my result

enter image description here

hoogw
  • 4,982
  • 1
  • 37
  • 33
0

Easy solutions on w3school, here is link

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  background: #04AA6D;
  cursor: pointer;
}

.slider::-moz-range-thumb {
  width: 25px;
  height: 25px;
  background: #04AA6D;
  cursor: pointer;
}
Hyzyr
  • 568
  • 4
  • 13