The Secret Focus in CSS

Not that kind of focus. This is about the difference between :focus and :focus-visible.

Most controls react similarly when clicked or tabbed to, but there is an important difference:

  1. :focus applies whenever an element receives focus (mouse or keyboard).
  2. :focus-visible appears when focus indication is needed, typically during keyboard navigation.

With :focus, users can see a ring even after mouse click.

Here is how :focus behaves:

Focus example 1
Focus state using
Focus example 2
Another behavior example

Now with :focus-visible:

Focus-visible example 1
Focus state using
Focus-visible example 2
Another behavior example

Small details like this are noticeable in real usage and improve perceived quality.

Practical tips for improving digital products

Learn new ways to improve your product’s design and usability with simple, practical ideas. For designers, developers, founders, and everyone who works with user interfaces

No spam or ads, unsubscribe any time.