HTML Table Sizes
In this page:
<table style="width: 100%;">
<tr>
<th style="width: 50%;">Header</th>
</tr>
</table>
Setting Overall Table Width
By default, a table shrinks to only as wide as its content requires.
Setting width: 100% on the table element makes it stretch to fill the full width of its containing element instead, which is the most common table width setting on modern responsive pages.
Example: Setting Overall Table Width
<table style="width: 100%;">
<tr><td>Full width table</td></tr>
</table>
Sizing Individual Columns
Setting a width value on a cell in the table's first row is the standard technique browsers use to size an entire column, since column width is a property of the whole column, not just one cell -- values on later rows for the same column are typically ignored.
Example: Sizing Individual Columns
<table>
<tr>
<th style="width: 70%;">Name</th>
<th style="width: 30%;">Age</th>
</tr>
</table>
Setting Row Height
height on a <tr> or a cell inside it sets a minimum row height -- the row will grow taller than the specified value if its content needs more space, but it will never shrink below the given height, which is useful for keeping table rows visually consistent even when some cells hold more content than others.
Example: Setting Row Height
<table>
<tr style="height: 50px;">
<td>Tall row</td>
</tr>
</table>
The table-layout Property
table-layout: auto (the default) makes the browser measure every cell's content across the whole table before finalizing column widths, which can be slow on very large tables. table-layout: fixed instead uses only the first row's widths (or equal division if none are set) immediately, rendering faster and enforcing strict column widths regardless of later content.
Example: The table-layout Property
<table style="table-layout: fixed; width: 100%;">
<tr>
<td>Fixed width column</td>
</tr>
</table>
Responsive Table Sizing
A table sized entirely with fixed pixel widths can overflow a narrow mobile screen, forcing awkward horizontal scrolling of the whole page layout.
Wrapping the table in a container with overflow-x: auto contains that horizontal scroll to just the table itself, keeping the rest of the page layout intact.
Example: Responsive Table Sizing
<div style="overflow-x: auto;">
<table style="width: 800px;">
<tr><td>Wide content</td></tr>
</table>
</div>
- Setting width on every td in a column and being confused when the values conflict, when only the first row's width values are actually used to size a column in most browsers.
- Using width: 100% on a table without table-layout: fixed, so the browser still measures every cell's content before finalizing column widths.
- Setting a fixed width narrower than a column's content actually needs, causing awkward text wrapping or overflow.
- width: 100% on a table makes it stretch to fill its container instead of shrinking to fit its content.
- Setting width on cells in the first row is the standard way to control individual column widths.
- table-layout: fixed speeds up rendering and enforces column widths strictly, ignoring later cell content sizes.
Table width, column sizing, and table-layout have been supported in every browser since the earliest CSS implementations.
Chapter Quiz — Complete all 26 topics to unlock
0/26 topics done
Complete these topics first:
- HTML Favicon
- HTML Page Title
- HTML Tables
- HTML Lists
- HTML Block & Inline
- HTML Comments
- HTML Colors
- HTML CSS
- HTML Links
- HTML Images
- HTML RGB Colors
- HTML HEX Colors
- HTML HSL Colors
- HTML Link Colors
- HTML Link Bookmarks
- HTML Background Images
- HTML Table Borders
- HTML Table Sizes
- HTML Table Headers
- HTML Table Padding & Spacing
- HTML Colspan & Rowspan
- HTML Table Styling
- HTML Table Colgroup
- HTML Unordered Lists
- HTML Ordered Lists
- HTML Other Lists / Description Lists