Change Mobile Safari Highlight Color with CSS

By  on  

I love the amount of extra customization afforded to us by WebKit. That also makes me love the fact that, for the most part, WebKit Mobile is the choice renderer used by mobile devices. One rarely used style property is -webkit-tap-highlight-color, which allows developers to change the default tap highlight color. Here's how to use it!

The CSS

/* light blue at 80% opacity */
html {
	-webkit-tap-highlight-color: rgba(201, 224, 253, 0.8);
}

/* change it for a div that has a similar background-color to the light blue tap color */
.blueDiv {
	-webkit-tap-highlight-color: rgba(251, 185, 250, 0.9);
}

Changing the -webkit-tap-highlight-color property value is the key! Also note that using RGBA color allows the extra dimension opacity for the highlight so that the color isn't so harsh.

In the case that you have an element which you'd prefer wasn't highlighted at all, you would code:

.myButton {
	-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

-webkit-tap-highlight-color obviously isn't a crucial property to change with each site but it's nice to have the ability to change the tap color, especially if you're using dark-colored backgrounds.

Recent Features

  • By
    Conquering Impostor Syndrome

    Two years ago I documented my struggles with Imposter Syndrome and the response was immense.  I received messages of support and commiseration from new web developers, veteran engineers, and even persons of all experience levels in other professions.  I've even caught myself reading the post...

  • By
    5 More HTML5 APIs You Didn’t Know Existed

    The HTML5 revolution has provided us some awesome JavaScript and HTML APIs.  Some are APIs we knew we've needed for years, others are cutting edge mobile and desktop helpers.  Regardless of API strength or purpose, anything to help us better do our job is a...

Incredible Demos

  • By
    Dynamically Create Charts Using MooTools MilkChart and Google Analytics

    The prospect of creating graphics charts with JavaScript is exciting. It's also the perfect use of JavaScript -- creating non-essential features with unobtrusive scripting. I've created a mix of PHP (the Analytics class), HTML, and MooTools JavaScript that will connect to Google Analytics...

  • By
    NSFW Blocker Using MooTools and CSS

    One of my guilty pleasures is scoping out the latest celebrity gossip from PerezHilton.com, DListed.com, and JoBlo.com. Unfortunately, these sites occasionally post NSFW pictures which makes checking these sites on lunch a huge gamble -- a trip to HR's office could be just a click away. Since...

Discussion

  1. Thanks, David. However I don’t see the change in my experiment on my iPhone and using

    html {
      -webkit-tap-highlight-color: rgba(27, 75, 69, 1);
    }
    

    and inline version such as style=" -webkit-tap-highlight-color: rgba(27, 75, 69, 1);"

  2. Any idea how to disable this blink/highlight effect in Firefox OS app?

    • Try setting it to transparent?!

    • Yes I tried that on both body and anchor tags but it’s not working in Firefox OS simulator :(

    • -webkit is for Safari and Chrome browser only, and Mozilla -moz don’t have one for this.

  3. Can you tell me how to put a picture when highlighting?
    Can this be done using CSS3? or do i need to add js for when this is touched add a background pic?

  4. Shalabh

    Lovely!! I have been struggling with this issue to get rid of the highlight….This worked!!

  5. Aroos
    a:link { -webkit-tap-highlight-color: transparent; }
    

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!