209

Most of the time I'm not worried about it but I have an image carousel and if I click on the next and previous divs quickly, they will be highlighted in Chrome.

I tried using outline:none but no effect. Are there any solutions out there?

Smith
  • 2,904
  • 3
  • 19
  • 25
  • I do not see this effect on the current Chrome version – Billal Begueradj Sep 14 '18 at 11:29
  • 1
    I know that your use case is different, but for anyone else who might want to remove it from all links I do not recommend to do that. I have tried to remove it on a PWA, but without the visual feedback, the user perception is that the app is slower. – collimarco Nov 27 '19 at 21:19

8 Answers8

322

For Chrome on Android, you can use the -webkit-tap-highlight-color CSS property:

-webkit-tap-highlight-color is a non-standard CSS property that sets the color of the highlight that appears over a link while it's being tapped. The highlighting indicates to the user that their tap is being successfully recognized, and indicates which element they're tapping on.

To remove the highlighting completely, you can set the value to transparent:

-webkit-tap-highlight-color: transparent;

Be aware that this might have consequences on accessibility: see outlinenone.com

clemlatz
  • 7,543
  • 4
  • 37
  • 51
  • 4
    I found that when you run on a touchscreen for example, Chrome will behave much like it does on Android. I had a
    which would flash blue whenever you clicked somewhere inside it. Only when I used this answer did it stop. Thanks!
    – Valorum Jul 28 '16 at 20:37
  • 2
    None of the other css attys will do this. So important since the tap highlighting distorts the appearance of whatever is clicked, slurring your visual language. – Dominic Cerisano Sep 24 '16 at 21:52
  • 28
    `-webkit-tap-highlight-color: transparent;` seems to work too. – Bernard Apr 23 '17 at 14:59
  • 1
    I liked this, for touch events it is a must! This information has "out of chart" usefullness! – Berker Yüceer Feb 12 '20 at 12:15
  • Very useful. I tried out many different things but this worked well. – Shashikanth Reddy Sep 19 '20 at 07:00
  • 2
    For the sake of accessibility, it would be worth keeping some indicator that the link has been clicked. You could use rgba with a slight opacity (adjusted depending on what your initial link/button background colour is): `-webkit-tap-highlight-color:rgba(255, 255, 255, 0.2)` – paddyfields May 03 '22 at 09:25
290

You can use pure CSS to accomplish this. Here's a rundown for multi-browser support, chrome being covered by the first line and the final :focus bit. Details below.

.noSelect {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
.noSelect:focus {
    outline: none !important;
}

Simply add the class="noSelect" attribute to the element you wish to apply this class to. I would highly recommend giving this CSS solution a try. Some have suggested using JavaScript, but I believe this is the cleanest solution.

For Android/Safari mobile/Edge

-webkit-tap-highlight-color: transparent; is the additional rule you may be looking for. Affects Chrome desktop (esp. with touchscreen) and mobile devices. Here's a warning about using this non-standard property, as well as some accessibility concerns with suggestions. Best practice is to replace the highlight with your own styling.

UPDATE: Later versions of Chrome...

A commenter on this answer pointed out :focus { outline: none !important;} is needed for newer versions of Chrome. Answer adapted to include this, as well! Ah, ever-changing standards.

smts
  • 3,585
  • 1
  • 16
  • 14
76

I'm running Chrome version 60 and none of the previous CSS answers worked.

I found that Chrome was adding the blue highlight via the outline style. Adding the following CSS fixed it for me:

:focus {
    outline: none !important;
}
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Jeff L.
  • 890
  • 6
  • 4
38

But, sometimes, even with user-select and touch-callout turned off, cursor: pointer; may cause this effect, so, just set cursor: default; and it'll work.

GeorgeButter
  • 2,521
  • 1
  • 29
  • 47
Gustavo B.
  • 381
  • 3
  • 3
  • 8
    This is a correct answer, `cursor: pointer;` is really causing highlight. But `-webkit-tap-highlight-color: transparent;` is more universal solution. – yanot Jul 01 '17 at 20:55
  • 1
    @yanot: read the warning about `-webkit-tap-highlight-color` before labelling it a relatively *universal solution*: https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-tap-highlight-color – Hassan Baig Feb 03 '18 at 20:55
  • @HassanBaig I think it's obvious that I didn't mean *universal cross-browser*, but *in this context, i.e. across different versions of chrome* – yanot Feb 04 '18 at 17:05
  • 2
    thanks - none of the other solutions worked for me. Had to remove the cursor pointer to make the blue highlight go away – RVP Feb 20 '18 at 01:22
  • 3
    `cursor: default` did the trick for me when nothing else worked. – jarrodwhitley Jun 04 '19 at 18:31
7

To remove the blue overlay on mobiles, you can use one of the following:

-webkit-tap-highlight-color: transparent; /* transparent with keyword */
-webkit-tap-highlight-color: rgba(0,0,0,0); /* transparent with rgba */
-webkit-tap-highlight-color: hsla(0,0,0,0); /* transparent with hsla */
-webkit-tap-highlight-color: #00000000; /* transparent with hex with alpha */
-webkit-tap-highlight-color: #0000; /* transparent with short hex with alpha */

However, unlike other properties, you can't use

-webkit-tap-highlight-color: none; /* none keyword */

In DevTools, this will show up as an 'invalid property value' or something.


To remove the blue/black/orange outline when focused, use this:

:focus {
    outline: none; /* no outline - for most browsers */
    box-shadow: none; /* no box shadow - for some browsers or if you are using Bootstrap */
}

The reason why I removed the box-shadow is because Bootsrap (and some browsers) sometimes add it to focused elements, so you can remove it using this.

But if anyone is navigating with a keyboard, they will get very confused indeed, because they rely on this outline to navigate. So you can replace it instead

:focus {
    outline: 100px dotted #f0f; /* 100px dotted pink outline */
}

You can target taps on mobile using :hover or :active, so you could use those to help, possibly. Or it could get confusing.


Full code:

element {
    -webkit-tap-highlight-color: transparent; /* remove tap highlight */
}
element:focus {
    outline: none; /* remove outline */
    box-shadow: none; /* remove box shadow */
}

Other information:

  • If you would like to customise the -webkit-tap-highlight-color then you should set it to a semi-transparent color so the element underneath doesn't get hidden when tapped
  • Please don't remove the outline from focused elements, or add some more styles for them.
  • -webkit-tap-highlight-color has not got great browser support and is not standard. You can still use it, but watch out!
corn on the cob
  • 2,093
  • 3
  • 18
  • 29
2

I had similar issue with <input type="range" /> and I solved it with

-webkit-tap-highlight-color: transparent;

input[type="range"]{
  -webkit-tap-highlight-color: transparent;
}
 <input type="range" id="volume" name="demo"
         min="0" max="11">
  <label for="volume">Demo</label>
pdr0
  • 114
  • 1
  • 4
-2

Try creating a handler for select event on those elements and in the handler you can clear the selection.

Take a look at this:

Clear Text Selection with JavaScript

It's an example of clearing the selection. You'd only need to modify it to work only on the specific element that you need.

Community
  • 1
  • 1
Floremin
  • 3,969
  • 15
  • 20
  • So it can't be fixed by CSS, huh? Could I just clear the selected text inside my click handler? EDIT- Thanks for the example. This sucks that it has to be handled via javascript. I was hoping it was just a CSS issue. – Smith Jan 08 '14 at 18:29
  • 1
    Also, will this have any accessibility impact? – Smith Jan 08 '14 at 18:32
  • You could clear the text in the click handler, but take a look at @smts answer with pure CSS. – Floremin Jan 08 '14 at 18:37
  • This is what I was looking for. Thanks! – Groove Aug 04 '21 at 02:38
-10

This works the best for me:

.noSelect:hover {
  background-color: white;
}
nagy.zsolt.hun
  • 6,292
  • 12
  • 56
  • 95