As :checked
and :disabled
are element attributes you can alternatively use their attribute selector form instead of the pseudo selectors, but that would make your CSS a little less transparent.
UPDATE
As @Kaiido correctly commented, this solution did not account for checkboxes inside a <fieldset disabled>
, making it not work properly. I adjusted the code to work with and without a parent <fieldset>
either disabled
or not. The accepted answer, however, does not work correctly (for now).
input[type="checkbox"]:is(:not(:checked):disabled,
:not(:checked)[disabled],
:not([checked]):disabled,
:not([checked])[disabled]) {
outline: 3px solid green;
}
<p>no fieldset</p>
<input type="checkbox"> <label>unchecked</label><br>
<input type="checkbox" disabled> <label>unchecked disabled</label><br>
<input type="checkbox" checked> <label>checked</label><br>
<input type="checkbox" checked disabled> <label>checked disabled</label><br>
<br>
<fieldset>
<legend>fieldset</legend>
<input type="checkbox"> <label>unchecked</label><br>
<input type="checkbox" disabled> <label>unchecked disabled</label><br>
<input type="checkbox" checked> <label>checked</label><br>
<input type="checkbox" checked disabled> <label>checked disabled</label>
</fieldset>
<br>
<fieldset disabled>
<legend>fieldset disabled</legend>
<input type="checkbox"> <label>unchecked</label><br>
<input type="checkbox" disabled> <label>unchecked disabled</label><br>
<input type="checkbox" checked> <label>checked</label><br>
<input type="checkbox" checked disabled> <label>checked disabled</label>
</fieldset>