ARTICLE AD BOX
The problem is that browsers (especially Firefox) add their own focus outline, even if you remove outline in CSS. So you were still seeing a focus ring on mouse click.
To fix it, you have to turn off both the normal outline and Firefox’s special focus styles. After that, :focus-visible will only show the outline for keyboard focus.
Example:
function handleKeydown(e) {
if (e.key === "Tab") {
document.body.classList.add("using-keyboard");
}
}
function handleMousedown() {
document.body.classList.remove("using-keyboard");
}
document.addEventListener("keydown", handleKeydown);
document.addEventListener("mousedown", handleMousedown);
input:focus {
outline: none;
}
.using-keyboard input:focus {
outline: 1px solid black;
}
input::-moz-focus-inner {
border: 0;
}
<input type="text" />
18.3k8 gold badges49 silver badges147 bronze badges
New contributor
Jiyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.


