-
-
Notifications
You must be signed in to change notification settings - Fork 79.2k
Open
Labels
Description
Describe the issue
The :checked state for .form-check-input checkboxes cannot be styled dynamically using CSS variables.
The issue is that while the unchecked state uses a CSS variable (--bs-form-check-bg), the :checked state sets background-color and border-color directly with SASS variables ($form-check-input-checked-bg-color), which are compiled into a static color. This prevents runtime customization.
Problematic code in Bootstrap's SCSS (https://github.com/twbs/bootstrap/blob/main/scss/forms/_form-check.scss) :
&:checked {
background-color: $form-check-input-checked-bg-color;
border-color: $form-check-input-checked-border-color;
}
Proposed solution:
Replace the direct SASS variable assignment with a CSS variable. This would allow for dynamic theme adjustments at runtime.
Example of a potential fix:
SCSS
&:checked {
--#{$prefix}form-check-bg-checked: #{$form-check-input-checked-bg-color};
background-color: var(--#{$prefix}form-check-bg-checked);
}
pc
Reduced test cases
- Go to https://getbootstrap.com/docs/5.3/forms/checks-radios/#without-labels
- Check in inspection window unchecked checkbox:
.form-check-input
Specificity: (0,1,0)
{
--bs-form-check-bg: var(--bs-body-bg);
background-color: var(--bs-form-check-bg);
background-image: var(--bs-form-check-bg-image);
- Check in inspection window now checked checkbox:
.form-check-input:checked {
background-color: #0d6efd;
border-color: #0d6efd;
}
- If you set --bs-form-check-bg the unchecked checkbox will be changed (background) but checked checkbox not!
What operating system(s) are you seeing the problem on?
Windows
What browser(s) are you seeing the problem on?
Chrome
What version of Bootstrap are you using?
v5.3.7