::placeholder vs [placeholder] difference?

What is difference in two like when set a color for first and after second? Do same job with color: red; for example?


Can you give an example? ::placeholder represents an placeholder in CSS, what do you mean by [placeholder]

[placeholder] is means the element[placeholder] so for example input[placeholder] can select input that contain placeholder attribute. As i know but what the logic behind it? about ::placeholder is select text color? or?


It’s for styling the placeholder. This is why I asked re the attribute selector. So as you say, input[placeholder] lets you style an input element with a placeholder. ::placeholder is for styling the placeholder element itself, so just whatever style you want (that makes sense) same as any other element.

Well thanks by the way something like :disabled vs [disabled] can be style but what is the more common way to style for example a option tag and then is select the same then what is better?

:disabled is a state, like :hover or :focus. It is not an element.

::placeholder is a pseudo-element, like ::before or ::after. Note the double colon. input[placeholder] and ::placeholder are not different ways of referring to the same thing: the first one is an input element that has a placeholder, the second one is the placeholder. The placeholder is an element. The first one styles an input element, the second one styles a placeholder.

It can’t take the full set of properties that a normal element can: the allowable properties are the same as the ::first-line pseudo-element:

1 Like