The vast majority of a
s in my application have a custom :focus
style, and so they have outline: none
. However, in some cases I don't have a good custom alternative, and I want to override my custom style and use the browser's default focus style.
I tried using:
div.where-i-want-this-style a:focus {
outline: initial;
}
But this didn't give me an outline. In fact, when I remove the outline: none;
from higher up the cascade and toggle this line, I see that this line actually causes the outline to go away.
My theory is that initial
here actually uses the initial outline of the a
, not of a focused a
. That value is, essentially, none
.
Is there a value I can provide that means something like outline: default-focus-outline
?
Focus outline provides visual feedback for users who can't use a mouse, or have visual impairment, when using Tab on their keyboard for navigation. example.css. /* 🚫 don't do this */ :focus { outline: none; }
Using the CSS rule :focus { outline: none; } to remove an outline on an object causes the link or control to be focusable, but removes any visible indication of focus for keyboard users. Methods to remove it such as onfocus="blur()" result in keyboard users being unable to interact with the link or control.
The outline-width property is used to set the width of the outline. The outline-style property is used to set the line style for the outline. The outline-color property is used to set the color of the outline.
This feature is deprecated/obsolete and should not be used.
For the record, something I found to work in Chrome, but not Firefox:
a:focus {
outline-style: none;
}
div.where-i-want-this-style a:focus {
outline-style: auto;
}
This works because Chrome's initial value for outline-style
is pretty straightforward (auto
), and setting just that part to none
is enough to disable the default outline.
Unfortunately, Firefox appears to use a vastly different method for setting its default focus style. If I'm reading Firebug right, it may not be expressible in CSS, which means there's no way to get it back once it's overridden. Once I discovered that I didn't bother checking any other browsers.
I would suggest using :not()
to remove the default outline from all links except the class you want.
a:not(.default-outline):focus {
outline: none;
}
Here's a full example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With