0
0
CSSmarkup~20 mins

Active and focus states in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Active and Focus States Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
selector
intermediate
2:00remaining
Identify the selector for keyboard focus
Which CSS selector correctly styles an element when it receives keyboard focus?
A:visited
B:focus
C:active
D:hover
Attempts:
2 left
💡 Hint
Think about which state applies when you tab to an element.
🧠 Conceptual
intermediate
2:00remaining
Purpose of :active state
What does the :active CSS pseudo-class represent?
AWhen an element has been visited
BWhen an element is hovered by the mouse
CWhen an element is focused by keyboard
DWhen an element is being clicked or pressed
Attempts:
2 left
💡 Hint
Think about the moment you press down on a button.
rendering
advanced
2:00remaining
Visual difference between :focus and :active
Given this CSS, what color will the button text be when it is focused but not pressed?
CSS
button:focus { color: blue; }
button:active { color: red; }
ABlue
BRed
CBlack (default)
DPurple
Attempts:
2 left
💡 Hint
Focus and active states can have different styles; only one applies at a time.
accessibility
advanced
2:00remaining
Why is visible focus important?
Why should web developers always provide a visible focus style for interactive elements?
ATo improve mouse usability
BTo make the page load faster
CTo help keyboard users know which element is active
DTo prevent screen readers from reading content
Attempts:
2 left
💡 Hint
Think about users who navigate without a mouse.
📝 Syntax
expert
2:00remaining
Identify the error in this CSS for active and focus states
What error does this CSS cause?
button:focus, :active { background: yellow; }
CSS
button:focus, :active { background: yellow; }
ASyntaxError: Missing element before :active selector
BNo error; styles apply to button focus and any active element
CTypeError: Invalid pseudo-class usage
DRuntime error: Cannot apply styles to :active
Attempts:
2 left
💡 Hint
Check if all selectors have an element or class before the pseudo-class.