HTML/CSSBeginner#css#selectors

What is the difference between pseudo-classes and pseudo-elements?

Pseudo-classes (single colon, like :hover, :nth-child, :focus) select elements based on state or position. Pseudo-elements (double colon, like ::before, ::after, ::first-line) create or target a sub-part of an element that doesn't exist as a separate DOM node.

Example
a:hover { color: red; }
li:nth-child(odd) { background: #f5f5f5; }
.quote::before { content: '\201C'; }

Related Questions

1
HTML/CSSIntermediate#css#selectors

Explain the :nth-child() selector with examples.

Open
2
HTML/CSSIntermediate#css#selectors

What CSS attribute selectors are available?

Open
3
HTML/CSSIntermediate#css#selectors

What is the difference between adjacent sibling (+) and general sibling (~) combinators?

Open