Two difference between table background and table border in HTML and CSS


Two difference between table background and table border in HTML and CSS


In this article, we are going to tell about the two differences between table background and table border in HTML. Let's see below.


When working with HTML tables, it is important to understand the difference between the table background and table border.


The first difference is their purpose. The table background is used to set the background color or image of the entire table, while the table border is used to add a border around the table cells. The background can be set using the "background-color" or "background-image" CSS properties, while the border can be set using the "border" property.



<table border="1" bgcolor="green">
        <tr>
            <th>NAME</th>
            <th>AGE</th>
            <th>DEPARTMENT</th>
        </tr>
        <tr>
            <td>CHANDRA</td>
            <td>22</td>
            <td>CSE</td>
        </tr>
        <tr>
            <td>RAM</td>
            <td>22</td>
            <td>CSE</td>
        </tr>
       <tr>
            <td>ANBU</td>
            <td>24</td>
            <td>CSE</td>
        </tr>
     <tr>
            <td>ARAVINDH</td>
            <td>21</td>
            <td>ECE</td>
        </tr>
    </table>


Table Background color in CSS





table {
  border-collapse: collapse;
  width: 100%;
  background-color:gray;
}
tr:hover {background-color: #ccc;}



Table Border in CSS




table, th, td {
  border: 1px solid black;
}


The second difference is their location. The table background is located behind the table cells and their contents, while the table border is located around the outside of the table cells. This means that if a table cell has a background color set, it will be visible behind the cell's contents and the table border, while if a table cell has a border set, it will be visible around the outside of the cell's contents and the table background.


Table Background Image in HTML



<table width='100%'  background='images/bg1.jpg'>

<tr><td >
</td></tr>
<tr><td >
</td></tr>

</table>


Table Background Image in CSS



table { background: url("https://example.com/bg1.jpg") no-repeat; }


And the Finally, The table background is used to set the background color or image of the entire table, while the table border is used to add a border around the table cells. I hope you will understanding the difference between table background and table border. Thankyou.!


Previous Post Next Post