<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
p:active {
background-color: red;
}
</style>
</head>
<body>
<p >p:active</p>
<script>
document.querySelector('p').addEventListener('touchstart', function () {
this.style.backgroundColor = 'red'
});
document.querySelector('p').addEventListener('touchend', function () {
this.style.backgroundColor = 'transparent'
});
document.querySelector('p').addEventListener('mousedown', function () {
this.style.backgroundColor = 'red'
});
document.querySelector('p').addEventListener('mouseup', function () {
this.style.backgroundColor = 'transparent'
});
</script>
</body>
</html>