AI CSS Animations

Table Row Hover Effect

Hovering a cell tints its row, marks the row with an accent bar and faintly tints its column too. The row uses an inset shadow and the column a background, so the crossing cell stacks both.

Also known as: table row highlight on hover, table crosshair hover css, tr hover css.

CustomerPlanMRR
NorthwindTeam$480
GlobexPro$1,200
InitechStarter$90

HTML

<table class="hfx-table-row-highlight">
  <thead>
    <tr><th>Customer</th><th>Plan</th><th>MRR</th></tr>
  </thead>
  <tbody>
    <tr><td>Northwind</td><td>Team</td><td>$480</td></tr>
    <tr><td>Globex</td><td>Pro</td><td>$1,200</td></tr>
    <tr><td>Initech</td><td>Starter</td><td>$90</td></tr>
  </tbody>
</table>

CSS

.hfx-table-row-highlight {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  min-width: 19em;
  border-collapse: separate;
  border-spacing: 0;
  font-family: system-ui, sans-serif;
}
.hfx-table-row-highlight :is(th, td) {
  padding: 0.6em 1.1em;
  text-align: left;
  transition: background-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}
.hfx-table-row-highlight :is(th, td):last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.hfx-table-row-highlight th {
  border-bottom: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  color: color-mix(in srgb, currentColor 60%, transparent);
  font-size: 0.72em;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.hfx-table-row-highlight td {
  border-bottom: 1px solid color-mix(in srgb, var(--c) 12%, transparent);
  font-size: 0.9em;
}
.hfx-table-row-highlight td:first-child {
  position: relative;
  font-weight: 600;
}
.hfx-table-row-highlight td:first-child::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.4em;
  bottom: 0.4em;
  width: 0.2em;
  border-radius: 0.2em;
  background: var(--c);
  transform: scaleY(0);
  transition: transform 0.25s cubic-bezier(0.3, 0.7, 0.4, 1);
}
/* column: background */
.hfx-table-row-highlight:has(td:nth-child(1):hover) :is(th, td):nth-child(1),
.hfx-table-row-highlight:has(td:nth-child(2):hover) :is(th, td):nth-child(2),
.hfx-table-row-highlight:has(td:nth-child(3):hover) :is(th, td):nth-child(3) {
  background: color-mix(in srgb, var(--c) 7%, transparent);
}
.hfx-table-row-highlight:has(td:nth-child(1):hover) th:nth-child(1),
.hfx-table-row-highlight:has(td:nth-child(2):hover) th:nth-child(2),
.hfx-table-row-highlight:has(td:nth-child(3):hover) th:nth-child(3) {
  color: var(--c);
}
/* row: an inset shadow paints over the column tint, so the crossing cell is strongest */
.hfx-table-row-highlight tbody tr:hover td { box-shadow: inset 0 0 0 10em color-mix(in srgb, var(--c) 11%, transparent); }
.hfx-table-row-highlight tbody tr:hover td:first-child::before { transform: scaleY(1); }

@media (prefers-reduced-motion: reduce) {
  .hfx-table-row-highlight, .hfx-table-row-highlight *, .hfx-table-row-highlight::before, .hfx-table-row-highlight::after, .hfx-table-row-highlight *::before, .hfx-table-row-highlight *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --hfx-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --hfx-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar hover effects

Sliding Pill Nav Hover Effect
Directional Underline Nav Hover Effect
Dot Indicator Nav Hover Effect
Vertical Nav Indicator Hover Effect