HTML Form How to - Change checkbox color when checked








Question

We would like to know how to change checkbox color when checked.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
li {<!-- w w  w . j  a  v a 2s.  c  o m-->
  list-style-type: none;
}

input:checked+label {
  color: #bada55;
}
</style>
</head>
<body>
  <ul>
    <li><input id="check" type="checkbox" /> 
        <label for="check">Watch me change!</label></li>
    <li><input id="check" type="checkbox" /> 
        <label for="check">Watch me change!</label></li>
  </ul>
</body>
</html>

The code above is rendered as follows: