CSS Pseudo-selectors - Quick Guide
1. Pseudo-classes
1. Pseudo-classes (start with :)
| Pseudo-class | Description | Example |
|------------------|--------------------------------------|----------------------------------------|
| :hover | On mouse hover | a:hover { color: red; } |
| :active | When clicked | button:active { background: gray; } |
| :focus | When focused | input:focus { border: 2px solid blue; }|
| :nth-child(n) | Nth child element | li:nth-child(2) { color: green; } |
| :first-child | First child | p:first-child { font-weight: bold; } |
| :last-child | Last child | p:last-child { font-style: italic; } |
| :not(selector) | Not matching selector | div:not(.special) { color: gray; } |
| :checked | Checked inputs | input:checked { background: yellow; } |
| :disabled | Disabled elements | button:disabled { opacity: 0.5; } |
| :empty | No children inside | div:empty { display: none; } |
2. Pseudo-elements
2. Pseudo-elements (start with ::)
| Pseudo-element | Description | Example |
|------------------|--------------------------------------|------------------------------------------|
| ::before | Before content | p::before { content: "Text"; } |
| ::after | After content | p::after { content: " End"; } |
| ::first-letter | First letter | p::first-letter { font-size: 2em; } |
| ::first-line | First line of text | p::first-line { color: blue; } |
| ::selection | Text selection style | ::selection { background: yellow; } |
| ::placeholder | Placeholder text style | input::placeholder { color: gray; } |