HTML Form How to - Change text color when focused








Question

We would like to know how to change text color when focused.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.home:focus {<!--   ww w.  jav  a  2s .co m-->
  color: red;
}
</style>
</head>
<body>
  <input type="text" class="home" value="google.com" />
</body>
</html>

The code above is rendered as follows: