CSS3 規範明確區分:單冒號 (:) 用於偽類,雙冒號 (::) 用於偽元素。
A pseudo-element is made of two colons (::) followed by the name of the pseudo-element. This :: notation is introduced to establish a discrimination between pseudo-classes and pseudo-elements. For compatibility, user agents must also accept the previous one-colon notation for pseudo-elements introduced in CSS levels 1 and 2 (namely, :first-line, :first-letter, :before and :after). This compatibility is not allowed for the new pseudo-elements introduced in CSS level 3.
| 類型 | 關鍵字 | CSS Level | 單冒號 | 雙冒號 | 建議 |
|---|---|---|---|---|---|
| 偽類 | :hover | 1 | ✅ | ❌ | 單冒號 |
| :focus | 2 | ✅ | ❌ | 單冒號 | |
| :nth-child() | 3 | ✅ | ❌ | 單冒號 | |
| :not() | 3 | ✅ | ❌ | 單冒號 | |
| 偽元素 | ::before | 2 | ✅ (兼容) | ✅ | 雙冒號 |
| ::after | 2 | ✅ (兼容) | ✅ | 雙冒號 | |
| ::first-line | 1 | ✅ (兼容) | ✅ | 雙冒號 | |
| ::first-letter | 1 | ✅ (兼容) | ✅ | 雙冒號 | |
| ::selection | 3 | ❌ | ✅ | 必須雙冒號 | |
| ::placeholder | 3 | ❌ | ✅ | 必須雙冒號 |