0

I'm wondering is there any difference between using the :disabled CSS pseudo-class selector and the [disabled] CSS attribute selector (e.g. different browsers support or whatever) to apply styles on a disabled HTML input element or are they totally equivalent?

3
  • 2
    They are not totally equivalent. An element can get a different state without its attribute actually changing. When that happens, :disabled will work and [disabled] will not. Commented Dec 8, 2017 at 16:19
  • Refer to this : stackoverflow.com/questions/20141450/… Commented Dec 8, 2017 at 16:23
  • The other way around, a big difference is that :disabled (by default?) only works on input elements where as setting the disabled attribute will work on anything but doesn't have any default effect. In general you should stick to intended behaviours, so using :disabled would be the best practice. Commented Dec 8, 2017 at 16:25

2 Answers 2

0

:disabled is introduced in css3. [disabled] exists from css2.

I would prefer :disabled over [disabled], see this question from: Should I use CSS :disabled pseudo-class or [disabled] attribute selector or is it a matter of opinion?

Sign up to request clarification or add additional context in comments.

Comments

0

The :disabled approach is supported by browsers that support CSS3, while [disabled] is supported by browsers supporting CSS2 onward.

Browser support is very similar for both; the major difference being IE7 backward vs IE9 backward compatibility.

Likewise, the [disabled] approach is supported by native browsers in older mobile OS versions.

For more details, refer to:

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.