It is completely possible to make :focus
work with a keyboard, but making :active
function with a keyboard is a bit more challenging.
The :focus
pseudo-class is triggered when an element receives focus, such as when a user clicks on an input field with a mouse or tabs to it. Check out this example demonstrating how focus works with both mouse clicks and tab navigation: W3School Focus. For further information, visit MDN :focus.
On the other hand, :active
functions differently. It is activated between the moment when a user clicks and releases a mouse button. It is harder to replicate this behavior using a keyboard since there is no key equivalent of a press-and-hold action. As soon as a user presses the enter key, the link will open. You can see how :active
works in this example: W3School Active. For more details, visit MDN :active.
If you plan on using pseudo-classes for links, it is recommended to utilize :focus
as it will work effectively with both mouse interactions and tab key navigation.