HTML Table to Responsive DIV Converter
Convert HTML tables to responsive DIV structures with configurable options for headers, labels, dimensions, and CSS classes. Clean output ready for production.
About
HTML tables remain structurally rigid across viewports. A 6-column table on a 320px screen forces horizontal scroll or content truncation. Both destroy usability. This converter parses raw <table> markup via the browser's native DOMParser and reconstructs every <tr> and <td> into semantically equivalent <div> elements with BEM-style class names. Column headers are optionally injected as data-label attributes on each cell, enabling pure CSS responsive patterns where labels appear inline on narrow screens. The tool preserves element attributes, optional inline dimensions, and alternate-row marking for striped styling.
Limitations: the converter does not handle deeply nested tables (tables inside cells) beyond one level. Merged cells via colspan and rowspan are carried as attributes but the responsive label mapping assumes a uniform column count per row. Complex colgroup-based width distributions require manual CSS adjustment after conversion. Pro tip: test your output at 320px, 768px, and 1024px breakpoints before shipping to production.
Formulas
The conversion follows a deterministic node-mapping algorithm. Each table element is mapped to a DIV equivalent with a BEM naming convention:
<thead> โ <div class="div-table__header">
<tbody> โ <div class="div-table__body">
<tfoot> โ <div class="div-table__footer">
<tr> โ <div class="div-table__row">
<th> โ <div class="div-table__cell div-table__cell--header">
<td> โ <div class="div-table__cell">
When addDataLabels is TRUE, the label injection follows a column-index mapping. Let H = [h0, h1, โฆ, hnโ1] be the ordered text content of the header cells. For each body cell at column index i, the attribute data-label = hi is applied. If i โฅ n (more body columns than headers), no label is added.
When enableAltRows is TRUE, each row at zero-based index j within its section receives: if j mod 2 = 0 โ div-table__row--even, else โ div-table__row--odd.
Reference Data
| Option | Default | Type | Description |
|---|---|---|---|
| customHeaderTarget | th | CSS Selector | Targets header cells for label extraction. Use tr:first-child td if the table lacks <th> elements. |
| addLabelHeaders | FALSE | Boolean | Injects a <span class="div-table__label"> inside each body cell containing the corresponding column header text. |
| hideLabels | TRUE | Boolean | Adds display:none to label spans. Use CSS media queries to reveal them on small screens. |
| removeHeaders | FALSE | Boolean | Omits the original header row from the DIV output entirely. Useful when labels replace headers. |
| preserveDim | FALSE | Boolean | Copies explicit width and height attributes/styles from table cells to DIV cells as inline styles. |
| enableAltRows | FALSE | Boolean | Adds div-table__row--even and div-table__row--odd classes to alternating rows for zebra-stripe CSS. |
| classes | (empty) | String | Space-separated CSS classes appended to the root <div class="div-table"> wrapper element. |
| outputIndent | 2 spaces | Number | Number of spaces per indentation level in the formatted output HTML. |
| addDataLabels | TRUE | Boolean | Adds data-label="Header" attributes to each body cell for CSS ::before content selectors. |
| wrapSections | TRUE | Boolean | Wraps <thead>, <tbody>, and <tfoot> groups in corresponding div-table__header, div-table__body, div-table__footer wrappers. |
| stripScripts | TRUE | Boolean | Removes all <script> tags and on* event attributes from parsed input for security. |
| preserveClasses | TRUE | Boolean | Retains original CSS classes from <td> and <tr> elements alongside generated BEM classes. |