CSS :active
Pseudo-Class
The :active
pseudo-class in CSS applies styles when an element is being clicked or activated by the user.
1. Basic Usage
✅ Changing Button Color When Clicked
✅ The button turns red while being clicked.
2. Applying to Links (<a>
Tags)
✅ Styling Active Links
✅ The link turns green when clicked.
3. Applying to Any Element
✅ Making a Box Shrink on Click
✅ The box shrinks slightly when clicked.
4. Combining with Other Pseudo-Classes
✅ :hover
vs :active
✅ The button turns blue when hovered and red when clicked.
5. When to Use :active
?
✔ Interactive buttons
✔ Clickable elements
✔ Custom UI effects
6. Example – Animated Click Effect
✅ The button shrinks slightly and changes color when clicked.