CSS Reference ยท Lists, Tables and Generated Content
The table-layout property
Reference for the CSS table-layout property: how auto and fixed algorithms size table columns, when fixed is faster and more predictable, with a live comparison.
The table-layout property chooses how the browser works out the widths of table columns. With auto (the default), column widths depend on the content of every cell, so the browser must read the whole table before it can lay it out. With fixed, the widths come from the table's own width and the first row (or <col> elements), and the cell content never changes them.
table.data { table-layout: fixed; width: 100%; }
Try it
In the first table the long word forces its column to be wide, even stretching the table past 300px if needed. In the second, the table stays exactly 300px and each column gets a third; the long word is clipped.
Syntax
table-layout: auto | fixed;
| Initial value | auto |
| Applies to | Table elements (display: table and inline-table) |
| Inherited | No |
| Animatable | No |
| Computed value | As specified |
Values
| Value | Description |
|---|---|
auto |
Automatic algorithm. Column widths are computed from the contents of all cells, so large tables render only after all rows are known. |
fixed |
Fixed algorithm. Column widths come from <col> elements or the cells of the first row; remaining space is split evenly among columns without a width. Needs a table width other than auto to take effect. |
Usage notes
- Set a width.
table-layout: fixedonly triggers the fixed algorithm when the table'swidthis notauto. Withwidth: autothe browser falls back to automatic layout. - Set widths in the first row or on
<col>. Later rows cannot change a column. Give header cells (or<col>) explicit widths, such as percentages. - Handle overflow yourself. Content wider than its column spills over the next cell. Use
overflow-wrap: anywhere, oroverflow: hiddenwithtext-overflow: ellipsisandwhite-space: nowrap. - Performance. A fixed layout lets the browser render rows as they arrive, which helps very long tables.
- Predictable grids. It is the easy way to get equal-width columns, such as calendars.
- Responsive tables.
fixedoften keeps tables inside narrow containers, but clipped data may hurt readability; consider scrolling the table in a wrapper withoverflow-x: autoinstead.
Browser support
Supported in all browsers.