How to set HTML Table Width?

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

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 percentage (%). If no particular value is assigned for the width attribute, it takes up the space according to the content.

cell-and-table-width

HTML <table> Width Attribute

It is possible to adjust the height and width of tables and their individual cells by assigning values in pixels or percentages. To customize the width of an entire table, the width attribute is used for the <table> element, whereas, for individual cells, the attribute is used for the <td> element.

Syntax

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Table width in pixels(px)

Table width in percentage (%)

Attribute Values

The values that the width attribute supports are as follows:

  • pixels: It sets a fixed width to the table in pixels.
  • %: It sets the table width in percentage (%). Since percentage assigns a variable size determined by the proportion of the window, it causes tables to vary from browser to browser.

Examples

The width attribute can manipulate the width of the entire table, as well as the width of a single cell.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Example 1: A Table With a Fixed Width of 200 Pixels

The following code displays the HTML table width for two tables, one without a width attribute and another one that has a 200px width.

HTML

Output

table-with-fixed-width-200px

Example 2: Cell Width or Column width

The following code displays the HTML table width for two tables, one without a width attribute, and the other one with a width attribute assigned to a particular cell.

Note: Altering the width of one cell in a row or column affects all the corresponding cells in the table.

HTML

Output

cell-width

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data

Example 3: A Table With a Width of 50% of the Width of the Window

The following code displays the HTML table width for two tables, one without a width attribute and the other one with 50% width.

Note: Since % assigns values with respect to the window size, the dimensions of the tables vary from browser to browser.

HTML

Output

table-with-width-attribute-set

Learn More

Conclusion

  • The HTML Table Width is used to specify the width of a table or the width of a particular table cell.
  • If no particular value is set to the width attribute, it takes up the space of the longest single word in each cell.
  • The width attribute supports two values:
    • pixels
    • percentage (%)
  • The <table> width Attribute is not supported by HTML 5. Here, the CSS property width is used to set the table width.
  • The width attribute of <td> is deprecated in HTML 4.01.
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more