Active and Focus States Styling
📖 Scenario: You are creating a simple webpage with a button. You want the button to look different when a user clicks it (active state) and when the button is selected using the keyboard (focus state). This helps users know which element they are interacting with.
🎯 Goal: Build a webpage with a button that changes its background color when it is clicked (active state) and shows a visible outline when it is focused (focus state). This improves accessibility and user experience.
📋 What You'll Learn
Create a button element inside the HTML body.
Add CSS to style the button with a default background color.
Add CSS for the
:active pseudo-class to change the button's background color when clicked.Add CSS for the
:focus pseudo-class to add a visible outline when the button is focused.Ensure the focus outline is clearly visible for keyboard users.
💡 Why This Matters
🌍 Real World
Buttons with clear active and focus states help users understand when they are interacting with elements, especially for keyboard and assistive technology users.
💼 Career
Web developers must create accessible and user-friendly interfaces. Styling active and focus states is a fundamental skill for building interactive web pages.
Progress0 / 4 steps