3

I have noticed that this checkbox will sometimes display a blue highlight when checked on certain browsers. I'm not entirely sure where this comes from, as I have only managed to see this behavior from Safari on my iPhone, as well as Device Mode from Chrome Developer Tools. However, desktop Chrome and Firefox do not include the highlight at all.

enter image description here

.center {
 top: 50%;
 left: 50%;
 position: absolute;
 transform: translate(-50%, -50%);
}

.switch {
 width: 120px;
 height: 68px;
 position: relative;
 display: inline-block;
}

.switch input {
 visibility: hidden;
}

.slider {
 top: 0;
 left: 0;
 right: 0;
 bottom: 0;
 cursor: pointer;
 position: absolute;
 transition: 0.375s;
 border-radius: 68px;
 background-color: #414b55;
}

.slider:before {
 left: 8px;
 bottom: 8px;
 width: 52px;
 height: 52px;
 content: "";
 position: absolute;
 transition: 0.375s;
 border-radius: 50%;
 background-color: #ffffff;
}

input:checked + .slider {
 background-color: #fa6400;
}

input:checked + .slider:before {
 transform: translateX(52px);
}
<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Example</title>
 </head>
 <body>
  <div class="center">
   <label class="switch">
    <input type="checkbox">
    <span class="slider"></span>
   </label>
  </div>
 </body>
</html>

Could someone explain where it comes from and how to remove this effect?

Majestic Pixel
  • 111
  • 1
  • 9

1 Answers1

8

It may be the tap-highlight-color which you can make transparent with the following code:

.switch {
-webkit-tap-highlight-color: transparent
}

See also https://stackoverflow.com/a/21003770/753676 which mentions this and the user-select: none and -webkit-touch-callout: none approach.

But for Chrome on mobile you still need the -webkit-tap-highlight-color setting.