:active pseudo-class doesn't work in mobile safari

Jesse Rusak picture Jesse Rusak · Oct 7, 2010 · Viewed 89.9k times · Source

In Webkit on iPhone/iPad/iPod, specifying styling for an :active pseudo-class for an <a> tag doesn't trigger when you tap on the element. How can I get this to trigger? Example code:

<style> 
a:active { 
    background-color: red;
}
</style>
<!-- snip -->
<a href="#">Click me</a>

Answer

wilsonpage picture wilsonpage · Jan 16, 2012
<body ontouchstart="">
    ...
</body>

Applied just once, as opposed to every button element seemed to fix all buttons on the page. Alternatively you could use this small JS library called 'Fastclick'. It speed up click events on touch devices and takes care of this issue too.