Collapse Border for Table

To collapse border for table using CSS, set CSS border-collpase property of this table with the value collapse.

The following is the CSS to set border-collapse value.

table, th, td {
  border-collapse: collapse;
}

Examples

1 Collapse border for table

In the following example, we take a table with two columns, and three rows; and collapse the border.

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <style>
    table {
      border-collapse: collapse;
    }
    table, td, th {
      border: 1px solid red;
    }
  </style>
</head>
<body>
  <table>
    <thead>
      <tr>
        <th>Fruit</th>
        <th>Quantity</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Apple</td>
        <td>32</td>
      </tr>
      <tr>
        <td>Banana</td>
        <td>48</td>
      </tr>
      <tr>
        <td>Cherry</td>
        <td>75</td>
      </tr>
    </tbody>
  </table>
</body>
</html>

Conclusion

In this CSS Tutorial, we learned how to use CSS border-collapse property to collapse the borders between table contents into a single border, with examples.