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"
On this page

Example

#
CSS
.scores {
  width: 100%;
  table-layout: fixed;
}

.scores td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
Preview

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

#
Syntax
table-layout: auto | fixed;

Values

#
  • auto

    The column with the long text is the widest.
  • fixed

    All columns have equal width, regardless of content.

Values in practice

#

auto

The column with the long text is the widest.
.demo { table-layout: auto; }

fixed

All columns have equal width, regardless of content.
.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.