Change your table-layout to auto (or don't include it, as auto is the default).

A demo from MDN:

Answer from uber5001 on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ html โ€บ how-to-auto-adjust-table-td-width-from-the-content-in-html
How to Auto Adjust Table td Width from the Content in HTML? - GeeksforGeeks
July 26, 2025 - Example: The below example uses width: fit-content to Auto Adjust Table td Width from the Content in HTML. ... <!DOCTYPE html> <html lang="en"> <head> <title>Auto Adjust Table</title> <style> body { margin: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100vh; background-color: #f4f4f4; font-family: Arial, sans-serif; } h1 { color: green; text-align: center; font-size: 2em; margin: 20px 0; } h3 { color: #333; text-align: center; font-size: 1.2em; margin: 10px 0; } table { border-collapse: collapse; border: 1px solid #ccc; } th, td { border: 1px
People also ask

How do I make an HTML table responsive?
To make an HTML table responsive, use percentage-based widths, apply CSS media queries to adjust the layout for smaller screens, and enable overflow for horizontal scrolling when necessary.
๐ŸŒ
dhiwise.com
dhiwise.com โ€บ post โ€บ html-table-width-best-practices-for-a-modern-web-design
How to Set HTML Table Width For Responsive UI
Should I use fixed or percentage-based widths for HTML tables?
Itโ€™s best to use percentage-based widths for HTML tables, as they allow the table to adapt to various screen sizes, providing a more responsive and flexible design.
๐ŸŒ
dhiwise.com
dhiwise.com โ€บ post โ€บ html-table-width-best-practices-for-a-modern-web-design
How to Set HTML Table Width For Responsive UI
What is the role of CSS in responsive table design?
CSS plays a crucial role in responsive table design by allowing you to control widths, apply media queries, and manage layout changes like hiding columns or stacking rows for smaller screens.
๐ŸŒ
dhiwise.com
dhiwise.com โ€บ post โ€บ html-table-width-best-practices-for-a-modern-web-design
How to Set HTML Table Width For Responsive UI
๐ŸŒ
W3Schools
w3schools.com โ€บ html โ€บ html_table_sizes.asp
HTML Table Sizes
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 of a table, row or column.
๐ŸŒ
Symphony
support.symphony.com โ€บ hc โ€บ en-us โ€บ articles โ€บ 360016442352-Amend-the-column-width-of-an-HTML-table
Amend the column width of an HTML table โ€“ Symphony Help Center
The table-layout:auto parameter can be used to amend the width of user created HTML table columns.Note: By default, the width of the first column is set to 30%.To amend the column width, set the ta...
๐ŸŒ
SitePoint
sitepoint.com โ€บ html & css
Column widths to auto adjust for text? - HTML & CSS - SitePoint Forums | Web Development & Design Community
December 15, 2014 - Iโ€™m having trouble visualizing what makes this differ from default table behavior. ... If the text is non wrapping text then you set the cell to width:1px and use white-space:nowrap. The text in that column will then determine the width of ...
๐ŸŒ
CodeHim
codehim.com โ€บ home โ€บ html5 & css3 โ€บ html table column width auto adjust
HTML Table Column width Auto Adjust โ€” CodeHim
January 22, 2024 - This HTML and CSS code helps you to create a responsive table with auto adjust column width. It creates a clean, organized, and visually appealing table by styling various elements such as borders, fonts, colors, and spacing.
๐ŸŒ
CodePen
codepen.io โ€บ rightblog โ€บ pen โ€บ qaRred
CSS Table Column Autowidth
body{ font: 14px sans-serif; } table{ width:300px; font: 16px sans-serif; border-collapse: collapse; } td{ border: 1px solid #ccc; padding: 5px 10px; } table.autowidth td{ white-space:nowrap; }
Find elsewhere
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ CSS โ€บ Reference โ€บ Properties โ€บ table-layout
table-layout CSS property - MDN Web Docs - Mozilla
4 days ago - If the value of the width property is set to auto or is not specified, the browser uses the automatic table layout algorithm, in which case the fixed value has no effect. The fixed table layout algorithm is faster than the automatic layout algorithm because the horizontal layout of the table depends only on the table's width, the width of the columns, and borders or cell spacing.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ CSS โ€บ table-layout
table-layout - CSS - MDN Web Docs - Mozilla
If the value of the width property is set to auto or is not specified, the browser uses the automatic table layout algorithm, in which case the fixed value has no effect. The fixed table layout algorithm is faster than the automatic layout algorithm because the horizontal layout of the table depends only on the table's width, the width of the columns, and borders or cell spacing.
๐ŸŒ
DhiWise
dhiwise.com โ€บ post โ€บ html-table-width-best-practices-for-a-modern-web-design
How to Set HTML Table Width For Responsive UI
June 17, 2025 - Instead of relying on fixed pixel widths, use percentage values for both the table and its columns. This approach ensures that the table automatically adjusts to different screen sizes.
๐ŸŒ
HTML.com
html.com โ€บ attributes โ€บ td-width
Stop Using To Set Table Width In HTML: Here's Why ยป
January 24, 2020 - In both cases, your browser should give each column the same width. However, the first table should auto-size to fit the available space while the second will have a fixed width.
๐ŸŒ
MDBootstrap
mdbootstrap.com โ€บ standard โ€บ table column width
Bootstrap Table column width - free examples & tutorial
Add .w-auto class to the table element to set an auto width to the table column. The width of the columns will automatically adjust to the content of the column.
๐ŸŒ
Html5-tutorial
html5-tutorial.net โ€บ tables โ€บ changing-column-width
Changing Column Width - The complete HTML5 tutorial
<table border="1" width="100%"> <col style="width:40%"> <col style="width:30%"> <col style="width:30%"> <thead> <tr> <th>Fruits</th> <th>Vitamin A</th> <th>Vitamin C</th> </tr> </thead> <tbody> <tr> <th>Apples</th> <td>98 ui</td> <td>8.4 mg</td> </tr> <tr> <th>Oranges</th> <td>295 ui</td> <td>69.7 mg</td> </tr> <tr> <th>Bananas</th> <td>76 ui</td> <td>10.3 mg</td> </tr> </tbody> </table> This way, you can control how wide the columns of the table should be.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ html โ€บ how-to-fix-the-width-of-columns-in-the-table
How to fix the width of columns in the table ? - GeeksforGeeks
September 9, 2024 - Example 1: In this example, the first column's width is fixed, while others adjust based on screen size. If the fixed width is insufficient, the first column may overflow and behave like the others. ... <!DOCTYPE html> <html> <head> <style> table { margin-left: auto; margin-right: auto; font-size: 20px; height: 100%; table-layout: fixed; } td { border: 1px solid black; text-align: center; padding: 10px; } tr:nth-child(even) { background-color: #00cf45; } h1 { color: green; } </style> </head> <body> <center> <h1>GeeksforGeeks</h1> <h2> To fix the width of columns in the table </h2> <table> <tr
๐ŸŒ
W3Schools
w3schools.com โ€บ cssref โ€บ pr_tab_table-layout.php
CSS table-layout property
table.a { table-layout: auto; width: 180px; } table.b { table-layout: fixed; width: 180px; } Try it Yourself ยป ยท The table-layout property defines the algorithm used to lay out table cells, rows, and columns.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ CSS โ€บ Reference โ€บ Properties โ€บ column-width
column-width CSS property - MDN Web Docs - Mozilla
5 days ago - column-width = auto | <length [0,โˆž]> | min-content | max-content | fit-content( <length-percentage> ) <length-percentage> = <length> | <percentage>
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ CSS โ€บ column-width
column-width - CSS - MDN Web Docs - Mozilla
July 14, 2025 - column-width = auto | <length [0,โˆž]> | min-content | max-content | fit-content( <length-percentage> ) <length-percentage> = <length> | <percentage>