Performance: Table and data grid patterns
MEDIUM IMPACT
This affects page load speed and rendering performance by how many DOM nodes are created and how CSS styles are applied to table elements.
<table class="w-full border-collapse border border-gray-300"> <thead class="bg-gray-100"> <tr> <th class="p-2 text-left">Name</th> <th class="p-2 text-left">Age</th> <th class="p-2 text-left">City</th> </tr> </thead> <tbody class="divide-y divide-gray-200"> <!-- 100+ rows with minimal cell styling, using tbody divide for borders --> <tr> <td class="p-2">Alice</td> <td class="p-2">30</td> <td class="p-2">New York</td> </tr> <!-- ...more rows --> </tbody> </table>
<table class="w-full border-collapse border border-gray-300"> <thead> <tr> <th class="border border-gray-300 p-2">Name</th> <th class="border border-gray-300 p-2">Age</th> <th class="border border-gray-300 p-2">City</th> </tr> </thead> <tbody> <!-- 100+ rows with same heavy border and padding classes on every cell --> <tr> <td class="border border-gray-300 p-2">Alice</td> <td class="border border-gray-300 p-2">30</td> <td class="border border-gray-300 p-2">New York</td> </tr> <!-- ...more rows --> </tbody> </table>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy cell borders and padding on every cell | High (many styled nodes) | 100+ reflows for 100 rows | High paint cost due to many borders | [X] Bad |
| Border-collapse with row dividers and minimal cell padding | Moderate (fewer styled nodes) | Single reflow for borders | Low paint cost with simple styles | [OK] Good |