Set Background Color for Table Headings

To set a specific background color for the table headings using CSS, set CSS background-color property for the table heading th, with the required Color Value, like red, green, #f00, #ff552241, rgb(41, 85, 12), etc.

The CSS code to set background color for table headings is showing in the following.

</>
Copy
th {
  background-color: yellow;
}

Examples

1. Set yellow as background-color for table headings

In the following example, we take a table with two columns, and three rows; and set the background color of the table headings with yellow.

index.html

</>
Copy
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <style>
    th {
      background-color: yellow;
    }
    table, th, td {
      border: 1px solid;
      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 background-color property to set a specific background color for the table headings, with examples.