Performance: Active and focus states
This concept affects interaction responsiveness and visual stability during user input.
Jump into concepts and practice - no test required
button:focus-visible { outline: 2px solid #005fcc; } button:active { background-color: #004a99; }
button:focus, button:active { outline: none; box-shadow: 0 0 10px 5px rgba(0,0,0,0.5); border-width: 3px; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy box-shadow and border-width on :active/:focus | None | Multiple reflows per interaction | High paint cost due to shadows | [X] Bad |
| Outline and background-color changes on :focus-visible and :active | None | No reflows | Low paint cost | [OK] Good |
:active pseudo-class in CSS represent?:active:active pseudo-class applies when the user clicks or presses an element, like a button being pressed down.:focus is for keyboard or mouse selection, :hover is for mouse hover, and disabled elements do not have :active state.:focus selector applies styles when an element is selected by keyboard or mouse, such as tabbing to a button.:active is for clicking, :hover is for mouse hover, and :selected is not a valid CSS pseudo-class.button:active { color: red; }
button:focus { color: blue; }:active and :focus.button:focus comes after button:active, so color: blue applies.:active state takes precedence during the click, so the color is red while the button is pressed.a:active { background-color: green; }
a:focus { background-color: yellow; }a:focus and a:active have same specificity. The later rule in CSS overrides earlier if both apply.a:focus is declared after a:active, its background color overrides the active style.:active after :focusa:active after a:focus ensures active style shows during click.button:focus { outline: 3px solid blue; } is correct. Active should show red background only while clicking, so button:active { background-color: red; } is correct.