How can I customize bootstrap switch color to the desired color?
I found a oncolor
and offcolor
but not know how to change them.
In Bootstrap 4, the background color of the toggle switch is blue. This color can be changed by manipulating the custom-control-input class.
input[type=checkbox] does not not have a background-color property. You can use other ways to get your desirable result: You can use the checkbox inside a div and then style the div according to your needs.
We can add background color to a div by simply adding class “bg-primary”, “bg-success”, “bg-danger”, “bg-info”, and many more as shown in the following examples.
According to this page every option is also a method. So you can apply onColor and OffColor like that:
$("#sw").bootstrapSwitch({onColor: 'danger'});
or like that:
$("#sw").bootstrapSwitch();
...
$("#sw").bootstrapSwitch('onColor', 'danger');
or to override the default options of the library:
$.fn.bootstrapSwitch.defaults.onColor = 'danger';
To use your own colors you need to create your own CSS class. For example, this class uses 'retroorange' name with your color:
.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-retroorange,
.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-retroorange {
color: #fff;
background: #ff9933;
}
Then you can use 'retroorange'
in the usual way like that:
$("#sw").bootstrapSwitch({onColor: 'retroorange'});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With