Highlighting a Link When It’s Both Focused and Hovered in CSS
You can style a link only when it is both focused and hovered using a combined CSS pseudo-class selector. This allows you to apply specific styles only when both interaction states are active simultaneously.
Chain pseudo-classes like :hover and :focus together to target elements in both states.
This combination improves accessibility and user experience when navigating with both mouse and keyboard.
The order of pseudo-classes in the selector does not matter; a:focus:hover and a:hover:focus are equivalent.
In this example, the link changes color when hovered, shows an outline when focused, and highlights with a background color only when both conditions are met. This ensures clear visual feedback for users using both mouse and keyboard navigation.
Use :focus for keyboard accessibility and :hover for mouse interaction.
Combine them carefully to enhance interactivity without overwhelming the design.
Always maintain visible focus indicators for accessibility compliance.
Test with both mouse and keyboard to ensure consistent behavior.
How would you write CSS to highlight a link only when a user is both tabbing to it and hovering over it with a mouse?
What happens if you use :focus:hover instead of :focus-visible:hover — why might that break accessibility?
Our link highlights appear even when users navigate with a keyboard — how would you debug and fix this without breaking screen reader usability?
A designer says the link should highlight on hover but not on focus — but our accessibility audit says otherwise. How do you reconcile this?
We have a complex navigation component where links are dynamically rendered — how would you ensure the :focus-visible:hover style doesn’t cause layout shifts or performance jank on low-end devices?
In our design system, hover styles are inherited from a global theme — how would you isolate the focused-and-hovered state without creating specificity wars or breaking other components?
We’re migrating from a legacy CSS framework that uses JavaScript to simulate hover+focus states — how would you architect a clean, scalable CSS-only replacement that survives cross-team adoption and future accessibility regulations?
Our component library is used across 15+ products with different accessibility policies — how do you design the hover+focus highlight behavior to be configurable, testable, and maintainable at scale without forcing a one-size-fits-all solution?