HTML Form How to - Change style of an input when focus








Question

We would like to know how to change style of an input when focus.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
input {<!--  ww w  .  j  a  v  a  2  s  .  c  om-->
  border: 1px solid black;
}

input:focus {
  outline: none;
  border: 1px solid black;
  -webkit-box-shadow: inset 0 0 5px black;
}
</style>
</head>
<body>
  <input name="name" id="name" />
</body>
</html>

The code above is rendered as follows: