So I've noticed that if I create my own focus styles for (for example) a button, the styling will show after I've clicked the button with a mouse. But when I click a button with default focus styling, there is no outline.
However, you can perfectly tab through the buttons and both of them will show an outline when in focus.
I'm very curious of why default focus styling and my own focus styling does not function in the same way. Why does both appear on keyboard navigation, but only one of them appear on mouse click?
Please try out both clicking and navigating with keyboard on these buttons:
button {
padding: .5rem;
margin: 2rem;
}
.my-button:focus {
outline: 3px solid red;
}
<button type="button">
This button has default focus styling
</button>
<button type="button" class="my-button">
This button has my own focus styling
</button>
PS: I'm not interested in any javascript hacky solutions, or removing the focus styling in any way. I just want to learn why the web works this way.