CSS CSS Selectors Going Further with Attribute Selectors and Pseudo-Classes Element States Pseudo-Classes

Is it necessary to use an attribute selector for the checkbox?

I did just...

input:checked + label {
  font-weight: bold;

and it seemed to work fine. Is there any downside to not being as specific?

1 Answer

Steven Parker
Steven Parker
207,995 Points

Specificity affects the order of precedence of the rules. But in this case there seems to be no conflicting rule of higher specificity, so making this change should be fine.

Except for contributing to specificity, the attribute selector isn't needed here since only checkboxes have a "checked" state.