Horizontal Lines between Table Rows

To display horizontal lines between rows in a table using CSS, specify bottom border for the table cells: td and th.

The CSS code to set border-bottom for table cells th and td is showing in the following.

</>
Copy
th, td {
  border-bottom: 1px solid;
}

Examples

1. Border between rows of table

In the following example, we take a table with two columns, three rows, and set the bottom border of the rows with a border of width 1px, and solid style.

index.html

</>
Copy
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <style>
    th, td {
      border-bottom: 1px solid;
    }
    table, th, td {
      border-collapse: collapse;
      padding: 10px;
    }
  </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>

2. Color of the border between rows

We can also specify a color using border-bottom property.

index.html

</>
Copy
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <style>
    th, td {
      border-bottom: 1px solid red;
    }
    table, th, td {
      border-collapse: collapse;
      padding: 10px;
    }
  </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-bottom property to display lines between the table rows, with examples.