Open In App

HTML <td> width Attribute

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.






<!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:

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




<!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:

Supported Browsers

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.


Article Tags :