Open In App

HTML <td> width Attribute

Last Updated : 14 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML <td> width Attribute is used to specify the width of a table cell. If the width attribute is not set then it takes the default width according to the content.

It accepts values as pixels or percentages, enabling flexibility in defining cell widths based on specific requirements and using percentage values for cell width to create responsive tables that adapt to different screen sizes.

Note: The <td> width Attribute is not supported by HTML5.

Syntax

<td width="pixels | %">

Attribute Values

Attribute Values

Descriptions

pixels

It sets the width of the table in terms of pixels.

%

It sets the width of the table in terms of percentage (%).

Example: In this example, we will see the implementation of the <td> width attribute.

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML td width Attribute
    </title>
</head>
 
<body>
    <center>
        <h1 style="color: green;">
          GeeksforGeeks
          </h1>
 
        <h3 style="color: crimson;">
          HTML td width Attribute
          </h3>
 
        <table border="1" width="500">
            <tr>
                <th>NAME</th>
                <th>AGE</th>
                <th>BRANCH</th>
            </tr>
 
            <tr>
                <td width="50%">BITTU</td>
                <td width="20%">22</td>
                <td width="30%">CSE</td>
            </tr>
 
            <tr>
                <td>RAKESH</td>
                <td>25</td>
                <td>EC</td>
            </tr>
        </table>
    </center>
</body>
 
</html>


Output:

Screenshot-2023-12-14-121127

Example 2: In this example, we will see the implementation of the <td> width attribute.

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML td width Attribute
    </title>
</head>
 
<body>
    <center>
        <h1 style="color: green;">
          GeeksforGeeks
          </h1>
 
        <h3 style="color: crimson;">
          HTML td width Attribute
          </h3>
 
        <table border="1" width="80%">
            <tr>
                <th>NAME</th>
                <th>AGE</th>
                <th>BRANCH</th>
            </tr>
 
            <tr>
                <td width="40%">BITTU</td>
                <td width="30%">22</td>
                <td width="30%">CSE</td>
            </tr>
 
            <tr>
                <td width="60%">RAKESH</td>
                <td width="20%">25</td>
                <td width="20%">EC</td>
            </tr>
        </table>
    </center>
</body>
 
</html>


Output:

Screenshot-2023-12-14-121552

Supported Browsers

  • Google Chrome 1 and above
  • Microsoft Edge 12 and above
  • Firefox 1 and above
  • Opera 12.1 and above
  • Safari 1 and above

HTML is the foundation of webpages, is used for webpage development by structuring websites and web apps.You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads