Table of Contents

Table Backgrounds

You can set the table background using one of the following two ways.

  • bgcolor attribute –By Using this attribute to set background color for the whole table or just for one cell.
  • background attribute – By Using this attribute to set a background image for the whole table or just for one cell.
Example of Table Background color
<!DOCTYPE>
<html>
<body>
<table border="1" bgcolor="yellow">
<tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
<tr><td>Ram</td><td>singh</td><td>60</td></tr>
<tr><td>sonu</td><td>singh</td><td>80</td></tr>
<tr><td>Rakesh</td><td>Rajpoot</td><td>82</td></tr>
<tr><td>Amit</td><td>singh</td><td>72</td></tr>
</table>
</body>
</html>
Example of Table Background Image
<!DOCTYPE>
<html>
<body>
<table border="1" style="background-image: url('https://nielitbhu.com/image.jpg');height: 200px; width: 50%;">
<tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
<tr><td>Ram</td><td>singh</td><td>60</td></tr>
<tr><td>sonu</td><td>singh</td><td>80</td></tr>
<tr><td>Rakesh</td><td>Rajpoot</td><td>82</td></tr>
<tr><td>Amit</td><td>singh</td><td>72</td></tr>
</table>
</body>
</html>

Table Caption

  • The caption tag will use as a title orthe explanation for the table .
  • The table caption is shows up at the top of the table.
Example of Table Caption
<!DOCTYPE>
<html>
<body>
<table border="1">
<caption>Student Records<caption>
<tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
<tr><td>Ram</td><td>singh</td><td>60</td></tr>
<tr><td>sonu</td><td>singh</td><td>80</td></tr>
<tr><td>Rakesh</td><td>Rajpoot</td><td>82</td></tr>
<tr><td>Amit</td><td>singh</td><td>72</td></tr>
</table>
</body>
</html>