The CSS width property is used to set the width of a table. The width can be set: in percent (%); as a fixed length (px); by the auto keyword ......
In the realm of web development, tables are a staple for displaying data in rows and columns. Understanding how to control the width of these tables is crucial for creating visually appealing and responsive web pages. In this guide, we'll delve into the world of HTML tables and explore how CSS can help you manage their width.
By default, an HTML table will expand to fit its content. However, you can control its width using the width attribute in the <table> tag. The value can be set in pixels (px), percentages (%), or using the viewport's width (vw).
Here's a simple example:

| Width Attribute | Description |
|---|---|
width="500px" |
Sets the table's width to 500 pixels. |
width="100%" |
Makes the table span the full width of its container. |
width="50vw" |
Sets the table's width to 50% of the viewport's width. |
While the width attribute is useful, CSS provides more control over table width. You can apply CSS rules to the <table> element or its child elements (<td> and <th>).
You can use the width property in CSS to control the table's width. Here's how you can do it:
table {
width: 80%;
}
In this example, the table will take up 80% of the width of its parent container.

To control the width of individual columns, you can use the width property on the <td> and <th> elements. You can also use the table-layout property to change how the browser calculates the column widths.
Here's an example:
table {
table-layout: fixed;
}
th, td {
width: 20%;
}
In this case, the table layout is set to fixed, which means the column widths are set based on the width property. Each column will take up 20% of the table's width.
To create responsive tables that adapt to different screen sizes, you can use CSS media queries. Here's how you can adjust the table's width based on the viewport's width:
@media screen and (max-width: 600px) {
table {
width: 100%;
}
th, td {
width: auto;
}
}
In this example, when the viewport's width is 600 pixels or less, the table will span the full width of its container, and each column will take up the width it needs to display its content.
table-layout: fixed; to improve performance on large tables.In conclusion, mastering table width in HTML with CSS is essential for creating visually appealing and functional web pages. By understanding and applying the techniques discussed in this guide, you'll be well on your way to becoming a table width pro.
<strong>CSS Table Size (Width and Height) - W3Schools</strong><p>The CSS width property is used to set the width of a table. The width can be set: in percent (%); as a fixed length (px); by the auto keyword ...</p>
<strong>table-layout CSS property - MDN Web Docs - Mozilla</strong><p>20.04.2026 ... The fixed table layout algorithm is used. When using this keyword, the table's width needs to be specified explicitly using the width property.</p>
<strong>HTML Table Sizes - W3Schools</strong><p>HTML tables can have different sizes for each column, row or the entire table. Use the style attribute with the width or height properties to specify the size.</p>
<strong>How can I make a CSS table fit the screen width? - Stack Overflow</strong><p>21.11.2010 ... @define a width for the table then you won't get horizontal bar. · 6 · @T J Crowder; the horizontal bar might be because of an absolute width that ...</p>
<strong>HTML <table> width Attribute - GeeksforGeeks</strong><p>vor 5 Tagen ... The HTML <table> width attribute is used to specify the width of a table. The width can be set in pixels or percentage. It controls how wide the ...</p>
<strong>How to Set HTML Table Width For Responsive UI - DhiWise</strong><p>17.06.2025 ... Learn how to create responsive HTML tables that adapt to different screen sizes. Discover best practices for setting table widths, ...</p>
<strong>HTML Table Sizes - SitePoint</strong><p>How to limit table width in HTML? To limit a table's width, use the max-width property in CSS. This restricts the table's maximum width while allowing it to ...</p>
<strong>Tables - W3C</strong><p>Document languages other than HTML may not contain all the elements in the CSS 2.1 table model. ... table's width, the width of the columns, and borders or cell ...</p>
<strong>CSS tables column width : r/webdev - Reddit</strong><p>09.07.2024 ... [HTML - CSS] Prevent Table Cell Width To Fit Its Content. r/web_design. • 3y ago ...</p>
<strong>Fix html table width with CSS | Blog - Grafxflow</strong><p>Sometimes when outputting data in a table based layout you may find the size and width differ when going between pages depending on the content.</p>
<strong>table-layout - CSS-Tricks</strong><p>04.01.2017 ... fixed : With this value, the table's layout ignores the content and instead uses the table's width, any specified width of columns, and border ...</p>
<strong>Controlling Table Sizes in HTML5: A Comprehensive Guide with ...</strong><p>22.10.2023 ... CSS Properties for Table Size · width and height: The width and height CSS properties can be used to set the dimensions of the table, columns, or ...</p>
<strong>How to set table width in HTML? - TutorialsPoint</strong><p>16.03.2026 ... Table width in HTML is set using the style="width: value" attribute. Use percentage values like 50% or 100% for responsive designs, and pixel ...</p>
<strong>Set a table columns width - HTML & CSS - SitePoint Forums</strong><p>09.03.2012 ... To set column widths in a table you would attach the width to the <col> or <colgroup> tag by specifying a class on that tag and assigning a width to that class ...</p>
<strong>HTML Table Sizes - GeeksforGeeks</strong><p>05.08.2025 ... To set the size of the entire HTML table, you can use the style attribute with the width property. The width of the entire table is set to 50% ...</p>
<strong>How to Set HTML Table Width? - Scaler Topics</strong><p>03.05.2023 ... The HTML table width attribute is used to specify the width of a table or the width of a table cell. The width can be absolute as in pixels or relative as in ...</p>
<strong>table-layout - Tailwind CSS</strong><p>Using fixed column widths ... You can manually set the widths for some columns and the rest of the available width will be divided evenly amongst columns without ...</p>
<strong>Please help! Table width doesn't work (in both HTML and CSS).</strong><p>12.12.2012 ... If the width sum of the th/td elements exceed the table width, the table will stretch. Set the overflow property on the table to scroll.</p>
<strong>CSS table-layout property - W3Schools</strong><p>fixed, Sets a fixed table layout algorithm. The table and column widths are set by the widths of table and col or by the width of the first row of cells. Cells ...</p>
<strong>Table Width | colspan | HTML/CSS - YouTube</strong><p>03.03.2024 ... Learn how to use colspan to adjust the width of your HTML tables in this easy-to-follow tutorial for beginners. Master the basics of HTML ...</p>