We have already seen the article, How to fix the height of rows in the table.
The width of the columns i.e. td in a table can be fixed very easily. This can be done by adding the width attribute in the <td> tag. If the width is not specified, the width of the column changes according to the change in the content. The specifications of width for the columns can be in pixels, or percentage.
<td width ="px | %">
- The width attribute is used to set the width of a column. It is added in the <td> tag.
- The width should be specified according to the content, either in pixels or percentage.
- If the content in the column is large, it will overflow.
Example 1: In this example, the width of the first column is fixed, but the width of the other columns are not fixed. So, when we change the size of the screen, the width of the first column remains the same, but the width of the other column changes according to the content. However, if the specified width is not sufficiently large according to the content, this may not work, and the first column will overflow and behave similarly to the other column.
Output: Run the following code and change the screen-size to see the difference between the columns.
- Before changing the screen-size:
- After changing the screen-size:
Example 2: In this example, <td width =”%”> is used.
Output: The width of the column is set to “50%” , so even after changing the screen size, the width of the first column remains “50%”.
- Before changing screen-size:
- After changing screen-size:
- How to fix the height of rows in the table?
- How to create table with 100% width, with vertical scroll inside table body in HTML ?
- HTML width/height Attribute vs CSS width/height Property
- How to Fix a 401 Unauthorized Error?
- How to fix number of visible items in HTML dropdown and allow multiple selections ?
- Underscore.js _.fix() Method
- Lodash _.fix() Method
- How to fix SSL_ERROR_RX_RECORD_TOO_LONG on Mozilla Firefox ?
- How to Count Number of Rows and Columns in a Table Using jQuery?
- HTML | <table> width Attribute
- HTML | DOM Table width Property
- How to create equal width table cell using CSS ?
- How to set fixed width for <td> in a table ?
- How to add table row in a table using jQuery?
- How to remove table row from table using jQuery ?
- How to make Bootstrap table with sticky table head?
- How create table without using <table> tag ?
- CSS | grid-template-columns Property
- CSS | columns Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.