CSS Grid Layout & Table Rendering: Interoperability of the 'gap' Property
0 reputation · 20 Jan 2024, 20:11 UTC
0 reputation · 20 Jan 2024, 20:11 UTC
The objective is to determine whether the CSS Grid Layout gap property should uniformly apply to table elements, enabling developers to use a single spacing mechanism across grid and tabular contexts.
Current browsers (Chrome 96+, Firefox 91+, Safari 15+, Edge 96+) ignore gap when declared on a <table> element, treating it as non‑applicable. The CSS Grid spec allows the property on tables but does not mandate implementation, and no vendor has announced a change. Workarounds such as margin on <td> or pseudo‑elements add markup complexity and may affect performance.
The specification’s wording on table support remains ambiguous, and it is unclear whether table‑gap support will be added as a separate feature or deferred until a broader CSS Table Layout standard is finalized.
gap property be implemented for table elements within the current CSS Grid Layout spec?29275 reputation · 21 Jan 2024, 01:49 UTC
gap property be implemented for table elements?According to the current CSS Grid Layout spec, the gap property is syntactically allowed on any element, but browsers are not required to apply it to <table>. In Chrome 96+, Firefox 91+, Safari 15+, and Edge 96+, the property is ignored on tables and its computed value is reported as 0px. No vendor has announced a change, and the spec does not mandate implementation. Therefore, you should not rely on gap for table spacing in production.
Use table‑specific spacing mechanisms that work consistently across browsers:
border-collapse: separate; (default) and apply border-spacing: 1rem; on the <table>. This creates space between adjacent cells without affecting cell content.
padding: 0.5rem; to <td> and <th>. If you need to maintain exact cell widths, adjust box-sizing: border-box;.
display: grid; or display: flex; and apply gap: 1rem; to the container. The gap will separate the table from other elements, but not between cells.
For most layouts, border-spacing offers the simplest, most predictable result.
The CSS Table Layout specification is still evolving. No active proposal exists to add a dedicated gap property for tables, and no vendor has committed to implementing it. If a table‑gap feature is introduced, it would likely appear under the CSS Table Layout spec rather than the Grid spec, and a public implementation timeline is currently undefined.
If your design requires collapsed borders (border-collapse: collapse;), border-spacing will have no effect. In that case, consider using cell padding or a wrapper with gap to achieve the desired spacing.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.