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.

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:
- Clicking the "Select All" checkbox in the header toggles the checked state of all checkboxes in the body.
- Clicking an individual checkbox adds a "selected" class to its parent row (
tr
), allowing for visual highlighting with CSS. - 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:
- Bulk Selection: A master "Select All" checkbox controls all row selections.
- Individual Selection: Users can select or deselect single rows.
- Visual Highlighting: A CSS class is applied to selected rows for clear visual feedback.
- Dependency-Free: The logic is self-contained in vanilla JavaScript.
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: