Interactive States and Pseudo-elements
Style links and controls across hover, focus, active, checked, disabled, and generated decorative parts.
Pseudo-classes select elements in a state or relationship, while pseudo-elements select a generated or special part. State styling should reinforce native semantics rather than simulate them. A hover-only interface excludes keyboard and touch use, and generated content must not be the only source of essential information.
See the core pattern
Read this rule set from the outside in. Identify the inputs, the decision or transformation, and the result before changing it.
.button:hover { translate: 0 -2px; } .button:focus-visible { outline: 3px solid #ad5b00; outline-offset: 3px; } .button[aria-pressed='true']::before { content: '✓'; margin-inline-end: .5em; }Working rules
- Design default, hover, focus, active, and disabled states together
- Use generated content only for decoration or redundant cues
- Test state combinations such as focused and disabled
A common mistake
A pseudo-element cannot repair missing accessible names or turn a non-interactive element into a button.
Guided practice
Style a button whose selected state is clear with text, shape, and a redundant generated mark.
- Copy the example into the editable notebook below.