table-layout
Chooses the algorithm for computing table column widths: content-based or fixed.
- Initial value
auto- Inherited
- No
- Animatable
- no
- Applies to
- tables (display: table)
- JavaScript
element.style.tableLayout = "fixed"
Example
#.scores {
width: 100%;
table-layout: fixed;
}
.scores td {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}<table style="width: 100%; table-layout: fixed; border-collapse: collapse;">
<tr><td style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-bottom: 1px solid #333; padding: 6px;">Anna Smith-Montgomery</td><td style="border-bottom: 1px solid #333; padding: 6px;">1240</td><td style="border-bottom: 1px solid #333; padding: 6px;">Level 7</td></tr>
</table>Definition and usage
#With the default table-layout: auto, the browser reads the whole table content before computing column widths. Columns fit the longest content, which looks natural but can be slow for large tables.
With fixed, column widths are determined by the first row (or <col> elements) and the specified table width. The rest of the content doesnโt affect the layout, so the table renders faster and predictably.
fixed requires a table width to be set, for example width: 100%. Cell content that is too long may then overflow, so it is often combined with overflow-wrap or text truncation.
Syntax
#table-layout: auto | fixed;Values
#Values in practice
#auto
.demo { table-layout: auto; }fixed
.demo { table-layout: fixed; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Large tables with hundreds of rows render noticeably faster with
table-layout: fixed. - With
fixed, the most convenient way to set column widths is on<col>elements or on the cells of the first row.
Related entries
#Spotted a mistake or missing an example? Write to us.