Change Text Color of Table Row upon Hover

To change text color of the table row when user hovers over the row using mouse pointer, set the CSS color property with the required Color Value for the rows in table body.

The CSS code to set tbody tr:hover selector, for rows in table body, with required text color value is showing in the following.

</>
Copy
tbody tr:hover {
  color: red;
}

Examples

1. Set text color of table row to red on hover

In the following example, we take a table with two columns, three rows, and set the row’s text color to red when user hovers over a table row.

index.html

</>
Copy
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <style>
    tbody tr:hover {
      color: 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 :hover selector and color property to set a specific color for the content in table row, when mouse is hovered upon it, with examples.