About this snippet

Keep your data readable with sticky table headers. The header row stays fixed at the top as users scroll down the list, so they never lose track of what each column represents.

Size
1.3 KB
Uses
HTML, CSS
Loads
Nothing external
Views
548
<div class="table-wrapper">
  <table class="sticky-table">
    <thead>
      <tr>
        <th>Name</th>
        <th>Role</th>
        <th>Email</th>
        <th>Status</th>
      </tr>
    </thead>
    <tbody>
      <tr><td>Jane Doe</td><td>Developer</td><td>jane@example.com</td><td>Active</td></tr>
      <tr><td>John Smith</td><td>Designer</td><td>john@example.com</td><td>Active</td></tr>
      <tr><td>Sam Wilson</td><td>Manager</td><td>sam@example.com</td><td>Away</td></tr>
      <tr><td>Alice Cooper</td><td>Support</td><td>alice@example.com</td><td>Offline</td></tr>
      <!-- Add more rows to see effect -->
    </tbody>
  </table>
</div>
.table-wrapper {
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}
.sticky-table {
  width: 100%;
  border-collapse: collapse;
}
.sticky-table th {
  position: sticky;
  top: 0;
  background: #f9fafb;
  color: #374151;
  font-weight: 600;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 2px solid #e5e7eb;
  z-index: 10;
}
.sticky-table td {
  padding: 12px 16px;
  border-bottom: 1px solid #f3f4f6;
  color: #4b5563;
}
.sticky-table tr:last-child td {
  border-bottom: none;
}
Esc
↑↓ moveEnter select

Start from a template

Open an .html file, or HTML, CSS, JS, Markdown, Less or TypeScript files. You can also drop them here. Styles and scripts go into their panes.

Share

Source

Keyboard shortcuts

Save