Distinguishing between :focus and :active Pseudo-Classes
While both :focus and :active style states can be activated through user interaction, their functionality differs significantly.
:focus
:active
Key Differences
Example
Consider the following HTML and CSS code:
<button> Click to Change Color </button> <style> button { font-weight: normal; color: black; } button:focus { color: red; } button:active { font-weight: bold; } </style>
When the button is initially rendered, it has no active or focus state. When the user uses Tab to give it focus, it enters the :focus state and the text turns red. If the user then clicks the button, it enters the :active state, causing the text to turn red and bold.
The above is the detailed content of When Do You Use :focus and :active Pseudo-Classes?. For more information, please follow other related articles on the PHP Chinese website!