The HTML <th> width Attribute is used to specify the width of a table header cell. If the width attribute is not set then it takes the default width according to the content.
Note: It is not supported by HTML 5.
Syntax:
<th width="pixels | %">
Attribute Values:
Attributes values |
Description |
---|---|
pixels |
It sets the width of the table header cell in terms of pixels. |
% |
It sets the width of the table header cell in terms of percentage (%). |
Example: The implementation of th width
HTML
<!DOCTYPE html> < html >
< head >
< title >
HTML th width Attribute
</ title >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h2 >HTML th width Attribute</ h2 >
< table border = "1" width = "500" >
< tr >
< th width = "50%" >NAME</ th >
< th width = "20%" >AGE</ th >
< th width = "30%" >BRANCH</ th >
</ tr >
< tr >
< td >BITTU</ td >
< td >22</ td >
< td >CSE</ td >
</ tr >
< tr >
< td >RAKESH</ td >
< td >25</ td >
< td >EC</ td >
</ tr >
</ table >
</ body >
</ html >
|
Output:
Example: The implementation of th width.
HTML
<!DOCTYPE html> < html >
< head >
< title >Table with th Width Attribute</ title >
< style >
body {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
</ style >
</ head >
< body >
< h1 style = "color: green;" >GeeksforGeeks</ h1 >
< table border = "1" >
< tr >
< th width = "100" >Header 1</ th >
< th width = "200" >Header 2</ th >
< th >Header 3</ th >
</ tr >
< tr >
< td >Data 1</ td >
< td >Data 2</ td >
< td >Data 3</ td >
</ tr >
</ table >
</ body >
</ html >
|
Output: