CSS table-layout: Control Column Width with Fixed Table Layout
Use table-layout: fixed with a width if you want CSS to allocate the columns without measuring the contents of later rows. The default auto also uses cell content to size columns. With fixed layout, decide separately whether long values wrap or end in an ellipsis.
Why the table grows even with a width
In automatic layout, unbroken text, large images, and white-space: nowrap can raise the minimum column width and make a table wider than width: 500px. Fixed layout uses the <col> width first, then a specified width in the first row, and divides the remaining room among unsized columns. The table can still grow if the columns, borders, or spacing require more than the declared width. CSS 2.2 · Automatic table layout CSS 2.2 · Fixed table layout
Compare auto and fixed with the same data
Save the code as table-layout.html and open it in a browser. Both tables have the same filename and width: 500px. The first expands to fit the filename on one line. The second assigns 120px to the first column, gives the second column the remaining room, and displays an ellipsis at the end of the long value.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Compare table and column widths</title>
<style>
body { margin: 20px; font: 16px/1.6 system-ui, sans-serif; color: #203348; }
.jb-table-scroll { overflow-x: auto; margin-bottom: 24px; }
table { width: 500px; border-collapse: collapse; }
th, td { border: 1px solid #8a9bad; padding: 8px; text-align: left; }
th { background: #edf3fa; }
.filename { font-family: monospace; }
.auto .filename { white-space: nowrap; }
.fixed { table-layout: fixed; }
.fixed th:first-child { width: 120px; }
.fixed .filename {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<h1>Table width and long values</h1>
<div class="jb-table-scroll" tabindex="0" role="region" aria-labelledby="auto-caption">
<table class="jb-table-01 auto">
<caption id="auto-caption">auto: expands with content</caption>
<thead><tr><th scope="col">Type</th><th scope="col">Filename</th></tr></thead>
<tbody><tr><td>Document</td><td class="filename">quarterly-report-for-the-international-development-team-with-regional-appendices-and-budget-tables-2024.pdf</td></tr></tbody>
</table>
</div>
<div class="jb-table-scroll" tabindex="0" role="region" aria-labelledby="fixed-caption">
<table class="jb-table-01 fixed">
<caption id="fixed-caption">fixed: fits within 500px</caption>
<thead><tr><th scope="col">Type</th><th scope="col">Filename</th></tr></thead>
<tbody><tr><td>Document</td><td class="filename">quarterly-report-for-the-international-development-team-with-regional-appendices-and-budget-tables-2024.pdf</td></tr></tbody>
</table>
</div>
</body>
</html>
Compare the widths of the two table elements in developer tools. Turning off only text-overflow in the second table removes the ellipsis while the text remains clipped. In a narrow window, use Tab to focus each scroll area and the arrow keys to move horizontally.
Wrap or truncate long cells
To show the whole filename, replace the second table’s filename cell rule with the CSS below. white-space: normal allows wrapping, and overflow-wrap: anywhere can break unspaced strings. The column width stays the same and the row can grow taller.
.fixed .filename {
white-space: normal;
overflow-wrap: anywhere;
}
The ellipsis results from white-space: nowrap, overflow: hidden, and text-overflow: ellipsis working together. When readers need a clipped value, provide a way to expand it or view the full value in the details. CSS Overflow · text-overflow
Adjust column and table widths
Increase the first column from 120px to 160px. The second gets less space within the same 500px table. Restore 120px after comparing. To specify several column widths, put <col> elements inside a <colgroup>.
Use width: 100% for a table that follows its parent. A 120px first column can leave too little room for the second in a very narrow parent. Consider a percentage for the first column, or give the table a minimum width and a scroll area if numbers and dates need to stay on one line.




