524

I can make Firefox not display the ugly dotted focus outlines on links with this:

a:focus { 
    outline: none; 
}

But how can I do this for <button> tags as well? When I do this:

button:focus { 
    outline: none; 
}

the buttons still have the dotted focus outline when I click on them.

(and yes, I know this is a usability issue, but I would like to provide my own focus hints which are appropriate to the design instead of ugly grey dots)

thanksd
  • 54,176
  • 22
  • 157
  • 150
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
  • 2
    It seems like in Firefox 4, elements are no longer getting an outline by default when being clicked, but only when receiving keyboard focus. – Geert Apr 25 '11 at 07:56
  • 3
    What you call "ugly" is intended to support accessibility of a website. Keyboard only users can no longer determine which part of the website is in focus when removing this outline. Your website would be completely inaccessible and this should never be the case. Never remove the outline. Better style it in your way. – Markus Graf Mar 13 '19 at 13:19

25 Answers25

815
button::-moz-focus-inner {
  border: 0;
}
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
  • 16
    Yea it works for me too! Now how can it be done for selects ? – 7wp Feb 03 '10 at 19:54
  • 16
    Note that this also works for input (e.g. input::-moz-focus-inner {border:0;}) – El Yobo May 31 '10 at 07:03
  • yeah i needed this for input. i never seen the double colon used in CSS before. interesting. –  Aug 17 '10 at 09:44
  • 15
    Purpose of the double colon: (CSS3 notation) http://www.evotech.net/blog/2007/05/after-v-after-what-is-double-colon-notation/ – sholsinger Nov 03 '10 at 19:09
  • +1 Thank you so much for this CSS!! I could not find out how to do this... I was using `-moz-outline-style:` and it would not work and the text in my button was still being outlined. But this fixes it totally. Thanks so much!! – Nathan Sep 06 '11 at 23:26
  • I am testing this in a real world scenario with JAWs. I will get back to you all with any findings or hacks. Trust me there has been a lot of them. Whoever thought it would be a good idea to do an accessible tabs interface inside a modal is.. well.. need I say more. – John Drefahl Nov 01 '11 at 19:52
  • 27
    This one did not work for me, because bootstrap.css was making this ugly dotted buttons. Instead I have put `:focus {outline:none !important;}` – machineaddict May 02 '13 at 11:18
  • 5
    :focus {outline:none;} ::-moz-focus-inner {border:0;} would be less specific – Ben Jun 13 '13 at 12:17
  • In Firefox 23.0.1 it only works combined with `background: none`. http://jsbin.com/UMuRAso/1/edit – NVI Sep 20 '13 at 19:36
  • This doesn't work for `area`, For that I used this: http://stackoverflow.com/a/12888335/2615737 – Francisco Corrales Morales Apr 16 '14 at 15:14
  • doesn't work for me with the button selector. I had to use [type="button"] to get it to work. Idk why. – Xitcod13 Apr 19 '14 at 23:59
  • @7wp, if u used scss/less it would look like `button { ::-moz-focus-inner { border: 0; } }` – Gherman May 07 '14 at 10:29
  • @machineaddict that solved this issue for me, even though I am not using bootstrap.css - thank you! – user1380540 Jan 22 '15 at 16:37
  • How is this style applied inline? – Frederik Krautwald May 22 '15 at 23:41
  • I suggest to add the pseudo class `:-moz-focusring` – Mateng Aug 30 '17 at 11:02
  • in response to @7wp the SELECTS are done like that: `code select:-moz-focusring { color: transparent; text-shadow: 0 0 0 #000; } ` – Stan Oct 17 '17 at 14:58
  • however this method is not advisable to be used in production as specified [here](https://developer.mozilla.org/en-US/docs/Web/CSS/::-moz-focus-inner) – Vineet Mar 14 '20 at 16:56
  • @JoshCrozier is there any other way to do it? since this method is not recommended for production – Vineet Mar 17 '20 at 07:17
328

No need to define a selector.

:focus {outline:none;}
::-moz-focus-inner {border:0;}

However, this violates accessibility best practices from the W3C. The outline is there to help those navigating with keyboards.

https://www.w3.org/TR/WCAG20-TECHS/F78.html#F78-examples

Carl Vitullo
  • 853
  • 6
  • 15
Anderson Custódio
  • 3,297
  • 1
  • 14
  • 2
50

If you prefer to use CSS to get rid of the dotted outline:

/*for FireFox*/
    input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner
    {   
        border : 0;
    } 
/*for IE8 and below */
    input[type="submit"]:focus, input[type="button"]:focus
    {     
        outline : none; 
    }
Hugo Manrique
  • 40
  • 3
  • 8
chinkchink
  • 517
  • 4
  • 2
44

The below worked for me in case of LINKS, thought of sharing - in case someone is interested.

a, a:visited, a:focus, a:active, a:hover{
    outline:0 none !important;
}

Cheers!

thanksd
  • 54,176
  • 22
  • 157
  • 150
foxybagga
  • 4,184
  • 2
  • 34
  • 31
23
:focus, :active {
    outline: 0;
    border: 0;
}
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
blizzyx
  • 247
  • 2
  • 2
  • 1
    This wasn't specific enough, and I didn't want to use !important or target only `a` elements, so I found a good option to be `body :focus, body :active { outline: 0; border: 0; }` `::-moz-focus-inner { border: 0; }` – Ivan Durst Mar 28 '14 at 18:53
9

[Update] This solution doesn't work anymore. The solution that worked for me is this one https://stackoverflow.com/a/3844452/925560

The answer marked as correct didn't work with Firefox 24.0.

To remove Firefox's dotted outline on buttons and anchor tags I added the code below:

a:focus, a:active, 
button::-moz-focus-inner,
input[type="reset"]::-moz-focus-inner,
input[type="button"]::-moz-focus-inner,
input[type="submit"]::-moz-focus-inner,
select::-moz-focus-inner,
input[type="file"] > input[type="button"]::-moz-focus-inner {
    border: 0;
    outline : 0;
}

I found the solution here: http://aghoshb.com/articles/css-how-to-remove-firefoxs-dotted-outline-on-buttons-and-anchor-tags.html

Community
  • 1
  • 1
Renato Carvalho
  • 451
  • 2
  • 6
  • 14
9

Tried most of the answers here, but none of them worked for me. When I realized that I have to get rid of the blue outline on buttons on Chrome too, I found another solution. Remove blue border from css custom-styled button in Chrome

This code worked for me on Firefox version 30 on Windows 7. Perhaps it might help somebody else out there :)

button:focus {outline:0 !important;}
Community
  • 1
  • 1
Vartox
  • 189
  • 3
  • 12
7

This will get the range control:

:focus {
    outline:none;
}
::-moz-focus-inner {
    border:0;
}
input[type=range]::-moz-focus-outer {
    border: 0;
}

From: Remove dotted outline from range input element in Firefox

bob
  • 7,539
  • 2
  • 46
  • 42
6

There is many solutions found on the web for this, many of which work, but to force this, so that absolutely nothing can highlight/focus once a use the following:

::-moz-focus-inner, :active, :focus {
    outline:none;
    border:0;
    -moz-outline-style: none;
}

This just adds that little bit extra security & seals the deal!

thanksd
  • 54,176
  • 22
  • 157
  • 150
Shannon Hochkins
  • 11,763
  • 15
  • 62
  • 95
6

Tested on Firefox 46 and Chrome 49 using this code.

input:focus, textarea:focus, button:focus {
    outline: none !important;
}

Before (white dots are visible )

input with white dots

After ( White dots are invisible ) enter image description here

If you want to apply only on few input fields, buttons etc. Use the more specific code.

input[type=text] {
  outline: none !important;
}
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Madan Sapkota
  • 25,047
  • 11
  • 113
  • 117
6

There's no way to remove these dotted focus in Firefox using CSS.

If you have access to the computers where your webapplication works, go to about:config in Firefox and set browser.display.focus_ring_width to 0. Then Firefox won't show any dotted borders at all.

The following bug explains the topic: https://bugzilla.mozilla.org/show_bug.cgi?id=74225

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Vitaly Sharovatov
  • 922
  • 1
  • 8
  • 12
  • Thanks it working fine, but i have created so many links previously i never get this problem till now. but now i am in confused so what is the the reason previous to present ? – Durgaprasad Nov 16 '13 at 11:42
  • 1
    This is answer is now completely false. Setting the `::-moz-focus-inner {border:0;}` as mentioned in several other answers works perfectly. – Kelderic Sep 12 '14 at 14:39
  • @AndyM This answer does work. The solution presents in other answers is for CSS and only works for individual sites. – Rahil Wazir Oct 13 '14 at 12:01
  • 8
    The question asks how it can be done with CSS, and the answer says it can't be. That is false. It can be. – Kelderic Oct 13 '14 at 12:07
5

Simply add this css for select box

select:-moz-focusring {
    color: transparent;
    text-shadow: 0 0 0 #000;
}

This is working fine for me.

Abhay Singh
  • 1,595
  • 1
  • 23
  • 40
4

I think you should really know what you're doing by removing the focus outline, because it can mess it up for keyboard navigation and accessibility.

If you need to take it out because of a design issue, add a :focus state to the button that replaces this with some other visual cue, like, changing the border to a brighter color or something like that.

Sometimes I feel the need to take that annoying outline out, but I always prepare an alternate focus visual cue.

And never use the blur() js function. Use the ::-moz-focus-inner pseudo class.

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Flatline
  • 1,036
  • 1
  • 10
  • 17
4

In most cases without adding the !important to the CSS code, it won't work.

So, do not forget to add !important

a, a:active, a:focus{
    outline: none !important; /* Works in Firefox, Chrome, IE8 and above */
}


Or any other code:

button::-moz-focus-inner {
  border: 0 !important;
}
herci
  • 375
  • 1
  • 4
  • 24
3
button::-moz-focus-inner { border: 0; }

Where button can be whatever CSS selector for which you want to disable the behavior.

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
wavded
  • 31
  • 2
3

Remove dotted outline from links, button and input element.

a:focus, a:active,
button::-moz-focus-inner,
input[type="reset"]::-moz-focus-inner,
input[type="button"]::-moz-focus-inner,
input[type="submit"]::-moz-focus-inner {
    border: 0;
    outline : 0;
}
Fizer Khan
  • 88,237
  • 28
  • 143
  • 153
3

The CSS code below works to remove this:

a:focus, a:active, 
button::-moz-focus-inner,
input[type="reset"]::-moz-focus-inner,
input[type="button"]::-moz-focus-inner,
input[type="submit"]::-moz-focus-inner,
select::-moz-focus-inner,
input[type="file"] > input[type="button"]::-moz-focus-inner {
    border: 0;
    outline : 0;
}
magi182
  • 3,427
  • 1
  • 15
  • 23
kurumkan
  • 2,635
  • 3
  • 31
  • 55
3

If you have a border on a button and want to hide the dotted outline in Firefox without removing the border (and hence it's extra width on the button) you can use:

.button::-moz-focus-inner {
    border-color: transparent;
}
thanksd
  • 54,176
  • 22
  • 157
  • 150
Dave Everitt
  • 17,193
  • 6
  • 67
  • 97
3

You might want to intensify the focus rather than get rid of it.

button::-moz-focus-inner {border: 2px solid transparent;}

button:focus::-moz-focus-inner {border-color: blue} 
Jason Plank
  • 2,336
  • 5
  • 31
  • 40
  • 2
    @Nathan a little late but, not having any style in focus state will mess with keyboard experience. you won't be able to know what's focused when you're pressing *tab* key. – Hkan Nov 06 '15 at 10:21
  • @Hkan Yeah, I agree. But Firefox's outline is ugly especially when it is around a custom focus border. – Nathan Nov 06 '15 at 17:00
  • @Nathan I completely agree with that. What we should do is provide our own styling for focus state rather than making elements being the same on said state. – Hkan Nov 06 '15 at 17:27
2

It looks like the only way to achieve this is by setting

browser.display.focus_ring_width = 0

in about:config on a per browser basis.

AlexWilson
  • 1,179
  • 1
  • 9
  • 16
1

This works on firefox v-27.0

 .buttonClassName:focus {
  outline:none;
}
DPP
  • 12,716
  • 3
  • 49
  • 46
1

After trying many options from the above only the following worked for me.

*:focus, *:visited, *:active, *:hover  { outline:0 !important;}
*::-moz-focus-inner {border:0;}
Syed Waqas Bukhary
  • 5,130
  • 5
  • 47
  • 59
  • Actually (in Firefox 77 at least), you only need: ```button:focus { outline: none !important }``` Or if you like me don't like !important, this works also to override Firefox styling: ```:root button:focus { outline: none }``` – Jonas Sandstedt May 07 '20 at 14:06
1

Along with Bootstrap 3 I used this code. The second set of rules just undo what bootstrap does for focus/active buttons:

button::-moz-focus-inner {
  border: 0;    /*removes dotted lines around buttons*/
}

.btn.active.focus, .btn.active:focus, .btn.focus, .btn.focus:active, .btn:active:focus, .btn:focus{
  outline:0;
}

NOTE that your custom css file should come after Bootstrap css file in your html code to override it.

Ehsan88
  • 3,569
  • 5
  • 29
  • 52
1

Yep don't miss !important

button::-moz-focus-inner {
 border: 0 !important;
}
Riwaj Chalise
  • 637
  • 1
  • 13
  • 27
  • 1
    !important is not part of the answer here, and if your app needs it then you have bigger problems to solve than highlights around your buttons. Always strive to avoid !important. – monokrome Jul 17 '19 at 02:24
0

You can try button::-moz-focus-inner {border: 0px solid transparent;} in your CSS.

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
usual
  • 9
  • 1