The problem
You want custom focus styles that look good while maintaining keyboard accessibility.
The solution
/* Remove default, add custom focus */
:focus {
outline: none;
}
:focus-visible {
outline: 2px solid #3a7bff;
outline-offset: 2px;
}
/* Button focus ring */
.btn:focus-visible {
outline: none;
box-shadow:
0 0 0 3px #0d1126,
0 0 0 5px #3a7bff;
}
/* Input focus ring */
.input:focus-visible {
border-color: #3a7bff;
box-shadow: 0 0 0 3px rgba(58, 123, 255, 0.25);
}
/* Card focus with glow */
.card:focus-visible {
outline: none;
box-shadow:
0 0 0 2px #3a7bff,
0 0 20px rgba(58, 123, 255, 0.4);
}
/* Skip to content link */
.skip-link {
position: absolute;
top: -40px;
left: 0;
padding: 8px 16px;
background: #3a7bff;
color: white;
z-index: 1000;
transition: top 0.3s;
}
.skip-link:focus {
top: 0;
}See it live
Put it to work
<!-- Skip link for accessibility -->
<a href="#main-content" class="skip-link">Skip to main content</a>
<button class="btn">Focusable Button</button>
<a href="#" class="card">
<img src="image.jpg" alt="">
<h3>Focusable Card</h3>
</a>Worth knowing
:focus-visible only shows focus ring for keyboard navigation, not mouse clicks. Great for accessibility.