CSS table-layout Property

The CSS table-layout property determines which algorithm a browser uses to calculate the widths of columns in an HTML table.

It accepts two primary values: auto and fixed. The automatic layout algorithm considers table content when determining column widths, while the fixed layout algorithm uses specified widths and the first row to establish column sizing. Choosing the appropriate algorithm can improve layout predictability and rendering performance.

table-layout Syntax

The table-layout property accepts either auto or fixed, along with the standard CSS-wide keywords.

Basic Syntax

table {
  table-layout: fixed;
}

Automatic Layout

table {
  table-layout: auto;
}

The browser calculates column widths based on table content, available space, and applicable width constraints.

Fixed Layout

table {
  width: 100%;
  table-layout: fixed;
}

The browser uses the fixed table layout algorithm to determine column widths without examining the contents of every row.

CSS-Wide Keywords

table {
  table-layout: initial;
}
table {
  table-layout: inherit;
}
table {
  table-layout: unset;
}
table {
  table-layout: revert;
}
table {
  table-layout: revert-layer;
}

The initial value is auto.

Property Values

Value Description
auto Uses the automatic table layout algorithm, which considers table content when determining column widths.
fixed Uses the fixed table layout algorithm, which determines column widths from available width information rather than the contents of all rows.
initial Resets the property to auto.
inherit Uses the computed value from the parent element.
unset Resets the property to auto because it is not inherited.
revert Reverts the property according to CSS cascade origin rules.
revert-layer Reverts the property according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Initial value auto
Inherited No
Applies to Elements with display: table or display: inline-table
Computed value As specified
Animation type Discrete
Percentages Not accepted
Related properties width, border-collapse, border-spacing, overflow
Specification CSS 2.2

Valid Examples

table {
  table-layout: auto;
}
table {
  table-layout: fixed;
}
.data-table {
  width: 100%;
  table-layout: fixed;
}
table {
  table-layout: initial;
}

Invalid Examples

table {
  table-layout: flexible;
}
table {
  table-layout: 50%;
}
table {
  table-layout: 200px;
}
table {
  table-layout: auto fixed;
}

Unsupported keywords, lengths, percentages, and multiple values are invalid.

How It Works

The browser uses the selected table layout algorithm to distribute the available horizontal space among table columns.

Step 1: Create an HTML Table

<table class="example-table">
  <thead>
    <tr>
      <th>Name</th>
      <th>Description</th>
      <th>Status</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Project A</td>
      <td>A short description</td>
      <td>Active</td>
    </tr>
  </tbody>
</table>

Step 2: Use Automatic Layout

.example-table {
  width: 100%;
  table-layout: auto;
}

The browser considers the table's content when calculating column widths. A column containing longer text may receive more space.

Step 3: Switch to Fixed Layout

.example-table {
  width: 100%;
  table-layout: fixed;
}

The browser determines column widths using explicit column widths, applicable first-row widths, and the remaining available space.

Step 4: Add Column Widths

.example-table th:first-child {
  width: 25%;
}
.example-table th:last-child {
  width: 20%;
}

These widths influence the fixed layout calculation. The remaining space is allocated to the other column.

Important Consideration

The fixed algorithm is most useful when the table has an explicitly defined width. With an automatic table width, browsers use the automatic layout algorithm rather than the fixed algorithm.

Automatic Table Layout

The auto value uses the automatic table layout algorithm. Column widths are determined by considering cell content, specified widths, and the available table space.

Basic Example

table {
  width: 100%;
  table-layout: auto;
}

Content-Based Column Widths

A column containing long words, images, or other content may require more space than a column containing short labels.

Specified Column Widths

table {
  table-layout: auto;
}
th:first-child {
  width: 150px;
}

Specified widths influence the layout, but content requirements and other constraints can affect the final column sizes.

Advantages

  • Column widths adapt to their contents.
  • Longer content can receive additional space.
  • It works well when column widths are not predetermined.
  • It is the initial table layout algorithm.

Limitations

  • Column widths may change when content changes.
  • Large tables may require more layout calculations.
  • Column sizes may be less predictable.
  • Long unbreakable content can make a table wider than its container.

When to Use auto

Use auto when content-driven column sizing is more important than predetermined column widths.

Fixed Table Layout

The fixed value uses a faster, more predictable algorithm that does not require examining the contents of every table cell to determine column widths.

Basic Example

table {
  width: 100%;
  table-layout: fixed;
}

Column Width Calculation

The fixed layout algorithm determines column widths using the following information, in order:

  1. Explicit widths assigned to <col> elements.
  2. Otherwise, applicable widths assigned to cells in the first row.
  3. Remaining space distributed among columns without specified widths.

Equal Column Widths

.equal-columns {
  width: 100%;
  table-layout: fixed;
}

When no column widths are specified and the columns are otherwise unconstrained, the remaining space is distributed evenly.

Fixed Layout With Explicit Widths

.fixed-table {
  width: 600px;
  table-layout: fixed;
}
.fixed-table th:first-child {
  width: 150px;
}

The first column receives a specified width, while the remaining columns share the available space according to the fixed layout rules.

Advantages

  • Column widths are more predictable.
  • The browser does not need to inspect every row before determining column widths.
  • It can improve rendering performance for large tables.
  • It works well with explicit column widths.

Limitations

  • Long content may overflow its cell.
  • Content does not automatically receive additional column width.
  • Text wrapping or overflow handling may be necessary.
  • A defined table width is needed for the fixed algorithm to take effect.

When to Use fixed

Use fixed when predictable column widths and efficient rendering are more important than automatic content-based sizing.

Controlling Column Widths

Column widths can be influenced through <col> elements, first-row cells, and the table's available width.

Using colgroup

<table class="column-table">
  <colgroup>
    <col style="width: 25%;">
    <col style="width: 50%;">
    <col style="width: 25%;">
  </colgroup>
  <thead>
    <tr>
      <th>Name</th>
      <th>Description</th>
      <th>Status</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Project A</td>
      <td>Example description</td>
      <td>Active</td>
    </tr>
  </tbody>
</table>

CSS for the Table

.column-table {
  width: 100%;
  table-layout: fixed;
}

The <col> elements establish the intended proportions of the columns.

Using First-Row Cells

.column-table th:first-child {
  width: 25%;
}
.column-table th:last-child {
  width: 25%;
}

In fixed layout, first-row cell widths can determine column widths when corresponding column widths have not already been specified.

Using Pixel Widths

.column-table {
  width: 600px;
  table-layout: fixed;
}
.column-table th:first-child {
  width: 120px;
}

Pixel widths can be useful when a column requires a specific amount of horizontal space.

Using Percentage Widths

.column-table {
  width: 100%;
  table-layout: fixed;
}
.column-table th:first-child {
  width: 30%;
}

Percentage widths allow columns to occupy proportions of the table's available width.

Important Consideration

Column widths are still subject to table borders, spacing, minimum sizing constraints, and the fixed layout algorithm. Specified widths do not always guarantee exact final measurements.

Handling Content Overflow

Fixed table layout does not automatically expand columns to accommodate long content. Additional CSS may be needed to prevent overflow.

Wrapping Long Words

.fixed-table {
  width: 100%;
  table-layout: fixed;
}
.fixed-table th,
.fixed-table td {
  overflow-wrap: anywhere;
}

The overflow-wrap property allows long words or strings to break when necessary.

Truncating Text

.fixed-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

Long text can be clipped and displayed with an ellipsis when it exceeds the available cell width.

Allowing Horizontal Scrolling

.table-wrapper {
  max-width: 100%;
  overflow-x: auto;
}
.table-wrapper table {
  width: 700px;
  table-layout: fixed;
}

The wrapper allows users to scroll horizontally when the table is wider than the available space.

HTML Wrapper Example

<div class="table-wrapper">
  <table>
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
        <th>Status</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Project A</td>
        <td>A longer project description</td>
        <td>Active</td>
      </tr>
    </tbody>
  </table>
</div>

Important Consideration

Text truncation can hide important information. Prefer wrapping or scrolling when users need access to complete cell contents.

Layout Performance

The selected table layout algorithm can affect how much information a browser must examine before determining column widths.

Automatic Layout

The automatic algorithm considers content throughout the table, which may require additional calculations as rows are processed.

Fixed Layout

The fixed algorithm can determine column widths using explicit widths and the first row without waiting for all remaining cell contents.

Large Data Tables

.large-data-table {
  width: 100%;
  table-layout: fixed;
}

Fixed layout can be useful for tables containing many rows, particularly when column widths are known in advance.

Predictable Column Sizing

Because later rows do not determine column widths under fixed layout, content changes in those rows generally do not cause the columns to be recalculated based on their text.

Important Consideration

Fixed layout is not automatically the best choice for every table. The performance benefit depends on table complexity, available width information, and browser behavior.

Responsive Tables

Both table layout algorithms can be used in responsive designs. The appropriate choice depends on the amount of content and the desired column behavior.

Full-Width Table

.responsive-table {
  width: 100%;
  table-layout: auto;
}

The table uses the available container width while allowing content to influence column sizing.

Fixed Columns With Wrapping

.responsive-table {
  width: 100%;
  table-layout: fixed;
}
.responsive-table th,
.responsive-table td {
  overflow-wrap: anywhere;
}

Columns follow the fixed layout algorithm, and long text can wrap within the available space.

Scrollable Table

.responsive-table-wrapper {
  width: 100%;
  overflow-x: auto;
}
.responsive-table-wrapper table {
  min-width: 600px;
  width: 100%;
  table-layout: fixed;
}

The table maintains a minimum width and can scroll horizontally on narrow screens.

Switching Layout Algorithms

.responsive-table {
  width: 100%;
  table-layout: fixed;
}
@media (max-width: 600px) {
  .responsive-table {
    table-layout: auto;
  }
}

A media query can switch between fixed and automatic layout when different screen sizes require different column sizing behavior.

Important Consideration

Changing table-layout does not automatically make a wide table fit on a small screen. Content wrapping, column widths, and horizontal scrolling may still need attention.

Practical Examples

Content-Based Table

.content-table {
  width: 100%;
  table-layout: auto;
}

Allows column widths to respond to the content they contain.

Equal-Width Columns

.equal-table {
  width: 100%;
  table-layout: fixed;
}

Distributes available space evenly when no column widths are specified and no other constraints intervene.

Defined First Column

.defined-column-table {
  width: 100%;
  table-layout: fixed;
}
.defined-column-table th:first-child {
  width: 180px;
}

Reserves a specified width for the first column.

Percentage-Based Columns

.percentage-table {
  width: 100%;
  table-layout: fixed;
}
.percentage-table th:first-child {
  width: 30%;
}
.percentage-table th:last-child {
  width: 20%;
}

Assigns proportions to selected columns while leaving the remaining width for other columns.

Large Data Table

.data-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}
.data-table th,
.data-table td {
  padding: 8px;
  border: 1px solid #cbd5e1;
  overflow-wrap: anywhere;
}

Creates predictable column widths with wrapping for long cell contents.

Scrollable Table

.scroll-container {
  overflow-x: auto;
}
.scroll-container table {
  width: 800px;
  table-layout: fixed;
}

Allows a wide table to scroll horizontally within its container.

Truncated Table Cells

.truncated-table {
  width: 100%;
  table-layout: fixed;
}
.truncated-table td {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

Prevents long cell text from extending beyond the assigned column width.

Reset Table Layout

.default-table {
  table-layout: initial;
}

Restores the initial value of auto.

table-layout Example

This example compares two HTML tables containing identical data. The first uses automatic layout, while the second uses fixed layout.

HTML Example

<div class="table-layout-demo">
  <h4>table-layout: auto</h4>
  <table class="layout-auto">
    <thead>
      <tr>
        <th>ID</th>
        <th>Description</th>
        <th>Status</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1</td>
        <td>A longer description that influences column sizing</td>
        <td>Active</td>
      </tr>
    </tbody>
  </table>
  <h4>table-layout: fixed</h4>
  <table class="layout-fixed">
    <thead>
      <tr>
        <th>ID</th>
        <th>Description</th>
        <th>Status</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1</td>
        <td>A longer description that influences column sizing</td>
        <td>Active</td>
      </tr>
    </tbody>
  </table>
</div>

CSS Example

.table-layout-demo h4 {
  margin: 0 0 10px;
  font-size: 15px;
}
.table-layout-demo table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}
.table-layout-demo th,
.table-layout-demo td {
  padding: 10px;
  border: 1px solid #cbd5e1;
  text-align: left;
  overflow-wrap: anywhere;
}
.table-layout-demo th {
  background: #e2e8f0;
}
.table-layout-demo .layout-auto {
  table-layout: auto;
}
.table-layout-demo .layout-fixed {
  table-layout: fixed;
}
Browser Result

table-layout: auto

ID Description Status
1 A longer description that influences column sizing Active

table-layout: fixed

ID Description Status
1 A longer description that influences column sizing Active

The automatic table generally allocates more space to the description column because of its longer content. The fixed table distributes the available width evenly among the three columns because no explicit column widths are provided.

Comparing the Results

Feature auto fixed
Column sizing Content-based Based on explicit widths and first-row information
Content influence Content throughout the table Later-row content does not determine column widths
Predictability Varies with content More predictable
Potential performance May require more calculations Can determine widths earlier

Assigning a Fixed Column Width

.table-layout-demo .layout-fixed th:first-child {
  width: 15%;
}

The first column receives 15% of the table width, while the remaining space is distributed among the other columns.

Allowing Long Text to Overflow

.table-layout-demo .layout-fixed td {
  overflow-wrap: normal;
  white-space: nowrap;
}

Long text may extend beyond its assigned cell width unless additional overflow handling is applied.

Truncating Long Text

.table-layout-demo .layout-fixed td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

Long text is clipped and can display an ellipsis instead of overflowing its cell.

Switching Both Tables to Automatic Layout

.table-layout-demo .layout-auto,
.table-layout-demo .layout-fixed {
  table-layout: auto;
}

Both tables now use the automatic layout algorithm.

Accessibility Considerations

Table layout affects the visual presentation of data, but it does not replace the need for semantic HTML table markup.

Use Semantic Table Elements

Use <table>, <thead>, <tbody>, <th>, and <td> appropriately.

Identify Column Headers

<table>
  <thead>
    <tr>
      <th scope="col">Name</th>
      <th scope="col">Status</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Project A</td>
      <td>Active</td>
    </tr>
  </tbody>
</table>

The scope attribute helps associate header cells with their corresponding data cells.

Avoid Hiding Important Data

Text truncation can make information unavailable visually. Prefer wrapping or provide a way to access the complete content.

Support Small Screens and Zoom

Ensure that tables remain usable when users increase text size, zoom the page, or view the content on narrow screens.

Preserve Logical Reading Order

Keep table data in a meaningful row and column order so assistive technologies can interpret the relationships correctly.

Use Captions When Helpful

A <caption> element can identify the purpose of a data table and provide context for its contents.

Important Consideration

The table-layout property changes column sizing behavior, not the semantic relationships between table headers and data cells.

Common Mistakes

Using Unsupported Values

table {
  table-layout: flexible;
}

The property accepts auto and fixed, not flexible.

Using fixed Without a Defined Table Width

table {
  width: auto;
  table-layout: fixed;
}

With an automatic table width, the fixed layout algorithm does not take effect as intended.

Expecting fixed to Fit All Content

Fixed layout does not automatically expand columns to fit long text. Wrapping or overflow handling may be required.

Expecting auto to Produce Equal Columns

Automatic layout considers content, so columns may have different widths.

Applying table-layout to Individual Cells

td {
  table-layout: fixed;
}

The property controls table layout and should be applied to the table element or another element generating a table box.

Confusing table-layout With CSS Grid

The property controls table column sizing. It does not provide the layout capabilities of CSS Grid.

Ignoring Column Width Constraints

Explicit column widths, table borders, spacing, and other constraints can affect final column sizes.

Using Text Truncation Without an Alternative

Clipping cell contents can hide important information from users.

Ignoring Responsive Behavior

Wide tables may still overflow narrow screens regardless of the selected layout algorithm.

Assuming fixed Always Improves Performance

Fixed layout can reduce column-sizing work, but the actual performance benefit depends on the table and browser.

Important Considerations

Keep the following points in mind when using table-layout:

  • It determines which algorithm calculates table column widths.
  • The initial value is auto.
  • The property is not inherited.
  • It accepts auto and fixed.
  • The auto value considers table content.
  • The fixed value uses explicit widths and first-row information.
  • Fixed layout requires an appropriate defined table width.
  • Explicit <col> widths take priority in fixed layout.
  • First-row cell widths can determine column widths when column widths are not specified.
  • Remaining space is distributed among unconstrained columns.
  • Fixed layout can improve column-width predictability.
  • Fixed layout may reduce rendering work for large tables.
  • Automatic layout can adapt column widths to content.
  • Automatic layout may require more content measurements.
  • Long content may overflow fixed-width columns.
  • Text wrapping can help keep content within cells.
  • Text truncation can hide important information.
  • Horizontal scrolling can help accommodate wide tables.
  • Table borders and spacing can affect final dimensions.
  • Percentage column widths depend on available table space.
  • The property does not replace semantic HTML table markup.
  • It does not automatically make tables responsive.
  • It is not a replacement for CSS Grid or Flexbox.
  • It is discretely animated rather than smoothly interpolated.
  • Test column sizing with short and long content.
  • Verify readability at different viewport sizes and zoom levels.

Browser Support

The CSS table-layout property is widely supported in modern browsers, including Chrome, Edge, Firefox, and Safari.

Both auto and fixed have longstanding browser support. Minor differences in automatic column sizing can occur because the automatic table layout algorithm allows implementation flexibility.

For current compatibility information, visit Can I Use? and search for table-layout.

Feature Detection

@supports (table-layout: fixed) {
  .data-table {
    width: 100%;
    table-layout: fixed;
  }
}

Feature queries can test whether a browser recognizes the property and value syntax.

Fallback Behavior

If a declaration is invalid or unsupported, the browser ignores it. The table uses another applicable value from the cascade or the initial value of auto.

Testing Recommendations

Test automatic and fixed layouts, explicit column widths, long text, overflow behavior, and responsive table containers in the browsers you support.

Specifications

The table-layout property is defined in the CSS 2.2 specification.

CSS 2.2 - Table Width Algorithms

The specification describes automatic and fixed table layout algorithms, column width calculations, and how available table space is distributed.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: table-layout