CSS Hoverable Tables

Please Share On:

Definition:

CSS hover changes the table row effect on mouse hover. You can set your own hover background-color. In the below example, I chose a beige color.

Syntax:

tr:hover {
background-color: beige;
}

Source Code:

<!DOCTYPE html>
<html>
<head>
<style>
table {
  border-collapse: collapse;
  width: 100%;
}

table, th, td {
  border: 1px dotted red;
  }

th, td {
  padding: 8px;
  text-align: right;
}

th {
  background-color: darkmagenta;
  color: white;
}

tr:hover {
background-color: beige;
}

</style>
</head>
<body>

<h3>Example of CSS Hoverable Tables</h3>

<table>
  <tr>
    <th>Roll No.</th>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Hobby</th>
  </tr>
  <tr>
    <td>1.</td>
    <td>Harry</td>
    <td>Potter</td>
    <td>Acting</td>
  </tr>
  <tr>
    <td>2.</td>
    <td>Brad</td>
    <td>Pitt</td>
    <td>Acting</td>
  </tr>
  <tr>
    <td>3.</td>
    <td>David</td>
    <td>Warner</td>
    <td>Sports</td>
  </tr>
</table>

</body>
</html>

Output:

CSS hoverable on row 3



You may be interested in the following topics:

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright @2023. All Right Reserved.


Social media & sharing icons powered by UltimatelySocial