Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the purpose of the <code>:focus</code> pseudo-class in CSS?
The <code>:focus</code> pseudo-class styles an element when it has keyboard focus, helping users see which element is active for keyboard navigation.
Click to reveal answer
beginner
How does the <code>:active</code> pseudo-class differ from <code>:focus</code>?
:active styles an element while it is being clicked or pressed, whereas :focus styles an element when it is selected or ready to receive input.
Click to reveal answer
beginner
Why is it important to style focus states for interactive elements?
Styling focus states improves accessibility by helping keyboard and assistive technology users know which element is currently selected or ready for interaction.
Click to reveal answer
beginner
Which CSS property is commonly used to create a visible focus outline?
The outline property is commonly used to create a visible border around an element when it receives focus.
Click to reveal answer
intermediate
Can you combine :focus and :active selectors in CSS? What does it do?
Yes, combining :focus and :active styles an element when it is both focused and being clicked, providing clear visual feedback during interaction.
Click to reveal answer
Which CSS pseudo-class applies when a user clicks and holds a button?
A:hover
B:focus
C:active
D:visited
✗ Incorrect
:active applies while the element is being clicked or pressed.
What does the :focus pseudo-class help with?
AStyling elements when hovered by mouse
BStyling elements when disabled
CStyling elements after clicking
DStyling elements when keyboard focused
✗ Incorrect
:focus styles elements that have keyboard or programmatic focus.
Which CSS property is best for showing a clear focus outline?
Aoutline
Bborder
Cbackground-color
Dtext-decoration
✗ Incorrect
The outline property creates a visible border without affecting layout.
Why should you never remove focus outlines without replacement?
AIt makes keyboard navigation hard
BIt breaks page layout
CIt slows down page loading
DIt disables clicking
✗ Incorrect
Removing focus outlines without a visible alternative harms accessibility for keyboard users.
Which state is active when a user tabs to a link using the keyboard?
A:hover
B:focus
C:active
D:visited
✗ Incorrect
When tabbing, the element receives :focus to show it is selected.
Explain the difference between :focus and :active states in CSS and why both are important.
Think about keyboard navigation vs mouse clicking.
You got /4 concepts.
Describe how you would style a button to show a clear focus state that is accessible and visible on all devices.
Focus on visibility and accessibility.
You got /4 concepts.
Practice
(1/5)
1. What does the :active pseudo-class in CSS represent?
easy
A. An element that is currently selected by keyboard navigation
B. An element that is disabled and cannot be interacted with
C. An element that is hovered by the mouse pointer
D. An element being clicked or pressed by the user
Solution
Step 1: Understand the meaning of :active
The :active pseudo-class applies when the user clicks or presses an element, like a button being pressed down.
Step 2: Compare with other states
:focus is for keyboard or mouse selection, :hover is for mouse hover, and disabled elements do not have :active state.
Final Answer:
An element being clicked or pressed by the user -> Option D
Quick Check:
:active = clicked element [OK]
Hint: Active means element is being clicked or pressed [OK]
Common Mistakes:
Confusing :active with :focus
Thinking :active means hover
Assuming disabled elements have :active
2. Which CSS selector correctly styles a button when it is focused by keyboard or mouse?
easy
A. button:focus { outline: 2px solid blue; }
B. button:hover { outline: 2px solid blue; }
C. button:active { outline: 2px solid blue; }
D. button:selected { outline: 2px solid blue; }
Solution
Step 1: Identify the correct pseudo-class for focus
The :focus selector applies styles when an element is selected by keyboard or mouse, such as tabbing to a button.
Step 2: Check other options
:active is for clicking, :hover is for mouse hover, and :selected is not a valid CSS pseudo-class.
Final Answer:
button:focus { outline: 2px solid blue; } -> Option A
Quick Check:
:focus styles selected element [OK]
Hint: Focus uses :focus selector, not :active or :hover [OK]
Common Mistakes:
Using :active instead of :focus for keyboard selection
Confusing :hover with :focus
Using invalid :selected pseudo-class
3. Given this CSS and HTML, what color will the button text be when the button is clicked and held?
When the button is clicked and held, it matches both :active and :focus.
Step 2: Analyze CSS cascade
Both selectors have the same specificity. The rule declared later in the CSS wins. Here, button:focus comes after button:active, so color: blue applies.
Step 3: Verify actual browser behavior
However, in most browsers, the :active state takes precedence during the click, so the color is red while the button is pressed.
Final Answer:
Red -> Option A
Quick Check:
:active styles apply during click [OK]
Hint: :active styles apply while clicking, overriding :focus [OK]
Common Mistakes:
Believing :active always overrides :focus
Ignoring CSS declaration order
Assuming default color applies
4. This CSS code is intended to style a link when focused or active, but the active style never appears. What is the problem?
A. The :active selector must come before :focus in CSS
B. The link must have tabindex attribute for :active to work
C. The :focus style overrides :active because it comes later
D. The :active selector only works on buttons, not links
Solution
Step 1: Check CSS rule order and specificity
Both a:focus and a:active have same specificity. The later rule in CSS overrides earlier if both apply.
Step 2: Understand when :active and :focus apply
When clicking a link, it is both active and focused. Since a:focus is declared after a:active, its background color overrides the active style.
Step 3: Fix by placing :active after :focus
Reordering CSS to put a:active after a:focus ensures active style shows during click.
Final Answer:
The :focus style overrides :active because it comes later -> Option C
Quick Check:
Later CSS rule overrides earlier [OK]
Hint: Later CSS rules override earlier ones with same specificity [OK]
Common Mistakes:
Thinking :active only works on buttons
Believing tabindex affects :active
Ignoring CSS rule order
5. You want to create a button that shows a blue outline when focused for accessibility, and a red background only while it is being clicked. Which CSS code correctly achieves this?
D. button { outline: 3px solid blue; background-color: red; }
Solution
Step 1: Separate focus and active styles
Focus should show a blue outline, so button:focus { outline: 3px solid blue; } is correct. Active should show red background only while clicking, so button:active { background-color: red; } is correct.