Performance: Table color variants
This affects page load speed and rendering performance by adding CSS classes that change table row or cell colors.
<table class="table"> <tbody> <tr class="table-danger"><td>Row 1</td></tr> <tr class="table-success"><td>Row 2</td></tr> </tbody> </table>
<table class="table"> <tbody> <tr style="background-color: #f8d7da;"><td>Row 1</td></tr> <tr style="background-color: #d4edda;"><td>Row 2</td></tr> </tbody> </table>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline styles per row | Minimal | 0 | High (multiple paint calls) | [X] Bad |
| Bootstrap color classes | Minimal | 0 | Low (shared styles) | [OK] Good |
table-success for green, table-danger for red, table-warning for yellow, and table-info for blue.table-success.table-danger to color table rows red. To color a single cell, the recommended class is bg-danger which applies a red background color to any element.class='bg-danger' directly to the <td> element.<table class='table'> <tr><td>Row 1</td></tr> <tr class='table-warning'><td>Row 2</td></tr> <tr><td>Row 3</td></tr> </table>
<tr> has the class table-warning.table-warning adds a yellow background color to the row.<tr class='danger'> <td>Error Row</td> </tr>
table- for table color variants, so danger alone is invalid.table-danger.table-success and table-info classes directly to the <td> elements.<tr> will override or conflict, so color should be on cells.table-success and table-info for table color variants, not bg-success or bg-info.Pass the test and this pattern moves unknown