HTML Element Style How to - Change table background color








Question

We would like to know how to change table background color.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.tb {<!--from ww  w.jav  a 2s . c  o  m-->
  background-color: #EEE;
}
</style>
</head>
<body>
  <table class="tb">
    <tr>
      <td>first row</td>
    </tr>
    <tr>
      <td>second row</td>
    </tr>
    <tr>
      <td>third row</td>
    </tr>
  </table>
</body>
</html>

The code above is rendered as follows: