HTML Element Style How to - Style link when focused








Question

We would like to know how to style link when focused.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
a {<!--from  w w w. j  av a2  s .  co m-->
  color: #000;
}

a:focus {
  background-color: #000;
  color: #fff;
}
</style>
</head>
<body>
  <a href="#">a link</a>
</body>
</html>

The code above is rendered as follows: