For eliminating the blue overlay on mobile devices, you have several options available:
-webkit-tap-highlight-color: transparent; /* make it transparent using 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 and alpha */
-webkit-tap-highlight-color: #0000; /* transparent with short hex and alpha */
Unlike some other properties, you cannot employ
-webkit-tap-highlight-color: none; /* using 'none' keyword */
In DevTools, this may appear as an 'invalid property value' or something similar.
To get rid of the blue/black/orange outline when an element is focused, use the following code:
:focus {
outline: none; /* no outline - compatible with most browsers */
box-shadow: none; /* no box shadow - for specific browsers or in case of Bootstrap usage */
}
I removed the box-shadow
because at times Bootsrap (and certain browsers) automatically add it to focused elements, hence removing it using this method.
However, users navigating with a keyboard might face confusion since they rely on this outline for navigation. Therefore, consider replacing it instead with
:focus {
outline: 100px dotted #f0f; /* pink dashed outline of 100px thickness */
}
You can also direct taps on mobile devices by utilizing :hover or :active
, potentially assisting in providing guidance during interactions, although it could be perplexing.
Here's the complete code snippet:
element {
-webkit-tap-highlight-color: transparent; /* remove tap highlight */
}
element:focus {
outline: none; /* remove outline */
box-shadow: none; /* remove box shadow */
}
Additional insights:
- If customizing the
-webkit-tap-highlight-color
, opt for a semi-transparent color to ensure visibility of underlying elements upon tap.
- Kindly refrain from deleting the outline of focused elements, but rather consider enhancing their styles accordingly.
-webkit-tap-highlight-color
lacks comprehensive browser support and isn't standardized. While still usable, caution is advised!