VOOZH about

URL: https://www.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


  • Courses
  • Tutorials
  • Interview Prep

How to Auto Adjust Table td Width from the Content in HTML?

Last Updated : 26 Jul, 2025

HTML tables are needed to be displayed in responsiveness and adaptability across different screen sizes. Auto-adjusting table cell widths ensures that the table's layout adapts dynamically to the content, improving readability and usability. This can be done using different CSS properties like table layout and width, allowing for better control over how content fits within table cells.

these are the following approaches:

Using table-layout: auto

In this approach, we are using table-layout: auto to let the table columns dynamically adjust their widths based on the content inside each cell. This makes sure that each column width fits the content appropriately, allowing the table to be more responsive to varying data lengths and improving readability. The width: auto setting for the table ensures that it only takes up as much width as needed based on its content.

Example: The below example uses table-layout: auto to Auto Adjust Table td Width from the Content in HTML.

Output:

Using width: fit-content

In this approach, we are using width: fit-content for table cells to automatically adjust their width based on the content inside each cell. This approach makes sure that each cell's width precisely fits its content, which can be useful for tables with varying lengths of text or other elements, allowing the table to maintain a clean and organized appearance without extra spacing.

Example: The below example uses width: fit-content to Auto Adjust Table td Width from the Content in HTML.

Output:

Comment
Article Tags:
Article Tags: