Performance: State class generation (hover, active, disabled)
MEDIUM IMPACT
This affects the browser's style calculation and paint phases by adding or removing CSS classes that change element states like hover, active, or disabled.
@mixin button-states-good { button { &.hover { background-color: blue; } &.active { background-color: darkblue; } &.disabled { background-color: gray; cursor: not-allowed; } } } @include button-states-good; // JavaScript toggles classes on events instead of relying on :hover/:active pseudo-classes
@mixin button-states-bad { button { &:hover { background-color: blue; } &:active { background-color: darkblue; } &:disabled { background-color: gray; cursor: not-allowed; } } } @include button-states-bad;
| Pattern | DOM Operations | Style Recalc | Paint Cost | Verdict |
|---|---|---|---|---|
| Using :hover/:active/:disabled pseudo-classes | No extra DOM ops | Triggers style recalc and repaint on every hover/active | High paint cost on interaction | [X] Bad |
| Using explicit .hover/.active/.disabled classes toggled by JS | Class toggling on state change | Single style recalc per class toggle | Lower paint cost, batched updates | [OK] Good |