84

Does anybody know how to disable or manipulate the (in most browsers) dashed border of a dom-element if it has the focus in a tabindex order?

I want to build my own style for a focused element, but it would be great to use the existing feature, because with tabindex it is possible to bind keydown event to the dom-element.

moinudin
  • 134,091
  • 45
  • 190
  • 216
helle
  • 11,183
  • 9
  • 56
  • 83

9 Answers9

200

Just make a CSS rule for the elements you want that have outline:none;

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
43

CSS trick:

:focus { outline: none; }
goker
  • 2,690
  • 22
  • 20
  • 4
    Important to consider usability issues as soon as you are disabling a accessibility feature native in the browser. I suggest to create your own outline focus, like background color yellow. – blagus Mar 20 '18 at 01:53
5

With Firefox 53.0, if I disable the outline with one of the proposed solution, Firefox displays the default one.

However, if I use a blank color, it doesn't detect that the outline is hidden:

input:focus{
   outline: 1px solid rgba(255,255,255,1);
}
R3tep
  • 12,512
  • 10
  • 48
  • 75
hsyl20
  • 104
  • 1
  • 3
3
input::-moz-focus-inner { border: 0; }
moinudin
  • 134,091
  • 45
  • 190
  • 216
Mayur bhalgama
  • 265
  • 3
  • 10
2

Classic way is set outline to none:

outline: none;

However, it didn't work anymore on higher version browser or FireFox. This trick work for me:

outline: 0px solid transparent;

LOL. In future, if it detected transparent, then just replace with a little tiny higher transparent:

outline: 0px solid rgba(0,0,0,0.001);

Some browsers, it was a boxshadow too:

outline:none !important;
outline-width: 0 !important;
box-shadow: none;
-moz-box-shadow: none;
-webkit-box-shadow: none;
phnghue
  • 1,578
  • 2
  • 10
  • 9
1
a {
outline: 0;
}

a: hover,
a: active,
a: focus {
     outline: none;
}

input::-moz-focus-inner {
border: 0;
}
rotamota
  • 77
  • 1
  • 1
0

:focus state - Set the outline property to 0px solid transparent;

Mahendra Kulkarni
  • 1,437
  • 2
  • 26
  • 35
-4
$(function() {
     $('a').click(function() { $(this).blur(); });
     $('input').click(function() { $(this).blur(); });
});

Don't use CSS disable focus: http://outlinenone.com/ This use other users.

slva2000
  • 99
  • 4
  • 1
    why should I not use css? I see the point in your link, but your suggested solution will totally freak out the GUI and you wont be able, to access the fields. – helle Sep 24 '18 at 20:17
-8

Using jQuery you can do

$("#nav li a").focus(function(){
  $(this).blur();
});
Boris Delormas
  • 2,509
  • 1
  • 19
  • 27