Selectable Rows Table Template

Enable bulk actions by allowing users to select multiple rows with this interactive table.

This common UI pattern includes a checkbox for each row and a master "Select All" checkbox in the header, making it easy to perform actions on one or many items at once.

Screenshot of a table with a checkbox in each row and a 'select all' checkbox in the header.

Get Source Code → Preview →

About this Selectable Table

This template provides the HTML structure and JavaScript logic for row selection. The core components are an input with type="checkbox" in the header and in each row of the table body.

The JavaScript connects these elements:

  1. Clicking the "Select All" checkbox in the header toggles the checked state of all checkboxes in the body.
  2. Clicking an individual checkbox adds a "selected" class to its parent row (tr), allowing for visual highlighting with CSS.
  3. The script also intelligently updates the "Select All" checkbox: if all rows are checked manually, it becomes checked. If even one is unchecked, it becomes unchecked.

This is a fundamental pattern for any interface that supports bulk operations like "delete selected," "archive selected," or "export selected."

Key Features:

Implementation Notes:

The template provides the front-end selection logic. To make it functional, you would add your own JavaScript to a button (e.g., "Delete Selected") that finds all rows with the .row-selected class and performs an action with their data.

Code

Here's the full code, including the HTML structure and the JavaScript to manage the checkbox states:

View Output