How to change the checked color of a checkbox?


(Malsha Madushani Kalahewaththa

I want to change the color of the checked checkbox to green and the size should also change. But in my code, the size is changing but the color is not. I :checked:afteralso tried using

input[type='checkbox']{
    width: 16px !important;
    height: 16px !important;
    border-radius: 2px;
    border: 1px solid #7A7A9D;
    box-sizing: border-box;
  }
  
  input[type='checkbox']:checked{
    width: 100px !important;
    height: 100px !important;
    margin: 5px;
    color: red;
 
  }
Allen Reitz

Checkboxes are generally not considered to be styleable, but there are plenty of good ways to cheat. The W3C's "Custom Checkboxes" and "Radio Buttons" are a good place to start. It appears that the related SO question has many useful links.

I would use the more advanced CSS "+" selector

Also, using it !importantin CSS is often troublesome. In a few cases it helps, but in general it usually just causes trouble.

To answer your question directly:

input[type='checkbox'] {
  display: none;
}

input[type='checkbox']+span::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 2px;
  border: 1px solid #7A7A9D;
  box-sizing: border-box;
}

input[type='checkbox']:checked+span::before {
  width: 100px;
  height: 100px;
  margin: 5px;
  background: green;
}
<label>
  <input type="checkbox">
  <span>Eggs</span>
</label>

<label>
  <input type="checkbox">
  <span>Cheese</span>
</label>

<label class="custom-checkbox">
  <input type="checkbox">
  <span >Bacon</span>
</label>

Related


How to change the checked color of a checkbox?

(Malsha Madushani Kalahewaththa I want to change the color of the checked checkbox to green and the size should also change. But in my code, the size is changing but the color is not. I :checked:afteralso tried using input[type='checkbox']{ width: 16px !im

How to change the checked color of a checkbox?

(Malsha Madushani Kalahewaththa I want to change the color of the checked checkbox to green and the size should also change. But in my code, the size is changing but the color is not. I :checked:afteralso tried using input[type='checkbox']{ width: 16px !im

How to change the checked color of a checkbox?

(Malsha Madushani Kalahewaththa I want to change the color of the checked checkbox to green and the size should also change. But in my code, the size is changing but the color is not. I :checked:afteralso tried using input[type='checkbox']{ width: 16px !im

How to change the checked color of a checkbox?

(Malsha Madushani Kalahewaththa I want to change the color of the checked checkbox to green and the size should also change. But in my code, the size is changing but the color is not. I :checked:afteralso tried using input[type='checkbox']{ width: 16px !im

How to programmatically change checkbox checked color

user112016322: I am using the CheckBox view in Android. I want to change its color on inspection. Right now it's the default dark green when it's selected, I want to change it to something else, and make it the default if it's not selected. Here is my code: Ch

How to programmatically change checkbox checked color

user112016322: I am using the CheckBox view in Android. I want to change its color on inspection. Right now it's the default dark green when it's selected, I want to change it to something else, and make it the default if it's not selected. Here is my code: Ch

How to change color scheme when checkbox is checked?

Jan Czerny I am trying to implement light and dark mode for my website. It should load on the basis prefers-color-schemethat the user should be able to switch between these two modules . I have written this: <div id="theme-togle"> <input id="theme-toggle-d

How to programmatically change checkbox checked color

user112016322: I am using the CheckBox view in Android. I want to change its color on inspection. Right now it's the default dark green when it's selected, I want to change it to something else, and make it the default if it's not selected. Here is my code: Ch

Flutter: Change checked color of checkbox

SK7 I am trying to create a bottom sheet with checkboxes . I'm finding it hard to select checkboxes and display different colors after clicking. Currently, the checkbox remains empty. How can I fix this? bool isChecked = false; ... Column( ch

Flutter: Change checked color of checkbox

SK7 I am trying to create a bottom sheet with checkboxes . I'm finding it hard to select checkboxes and display different colors after clicking. Currently, the checkbox remains empty. How can I fix this? bool isChecked = false; ... Column( ch

Flutter: Change checked color of checkbox

SK7 I am trying to create a bottom sheet with checkboxes . I'm finding it hard to select checkboxes and display different colors after clicking. Currently, the checkbox remains empty. How can I fix this? bool isChecked = false; ... Column( ch

Change the color of the span if the checkbox is checked

BangulBangul In the to-do list app, the text color changes if you complete a to-do. I'm trying to do this, but have a problem. How can I do this with only pure css? .todo-item { display: flex; justify-items: space-between; align-items: center; gap: 10p

Flutter: Change checked color of checkbox

SK7 I am trying to create a bottom sheet with checkboxes . I'm finding it hard to select checkboxes and display different colors after clicking. Currently, the checkbox remains empty. How can I fix this? bool isChecked = false; ... Column( ch

Flutter: Change checked color of checkbox

SK7 I am trying to create a bottom sheet with checkboxes . I'm finding it hard to select checkboxes and display different colors after clicking. Currently, the checkbox remains empty. How can I fix this? bool isChecked = false; ... Column( ch

Flutter: Change checked color of checkbox

SK7 I am trying to create a bottom sheet with checkboxes . I'm finding it hard to select checkboxes and display different colors after clicking. Currently, the checkbox remains empty. How can I fix this? bool isChecked = false; ... Column( ch

Change checkbox color when checkbox is checked?

Tragon I want to use the default checkbox in my app, but I only want the checkbox color to be red when checked. I tried buttonTint but when unchecked it makes the box red so it doesn't work. basic A relatively easy way is to apply the theme to your checkboxes

Change checkbox color when checkbox is checked?

Tragon I want to use the default checkbox in my app, but I only want the checkbox color to be red when checked. I tried buttonTint but when unchecked it makes the box red so it doesn't work. basic A relatively easy way is to apply the theme to your checkboxes

How to change font color of order list when checkbox is checked?

Prasad I'm developing a list with carlist checkbox and uncheckbox and the list is in an array, I can't change the font color in the list using angularjs and html This is like doing list options page, the car list will have yes and no checkboxes but when i try

Change checkbox text color when checked

username I want to change the color of the text when the CheckBox is checked. Here is what I have now: <CheckBox android:id="@+id/checkbox" android:layout_width="20dp" android:layout_height="20dp" android:background="@drawable/states" andro