61

The 'height' and 'width' are not supported in HTML5. How can I set a td's width and height while conforming to the HTML5 standard?

<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>219 班網</title> </head> <body bgcolor="silver"> <div align="center"> <table> <tr> <td width="1000" height="250"> <object width="100%" height="100%" data="frameTop.html"></object> </td> </tr> </table> <table> <tr> <td width="300" height="700" > <object width="100%" height="100%" data="frameLeft.html"></object> </td> <td width="700" height="700"> <object width="100%" height="100%" data="frameRight.html"></object> </td> </tr> </table> </div> </body> </html> 
3
  • To any HTML/javascript people that the code is in C-style layout LOL Commented Oct 14, 2012 at 9:51
  • @Zyga So if I use CSS to assign width and height value, it won't be in conflict with HTNL5 standard? Commented Oct 14, 2012 at 9:53
  • Thats right, there is no conflict as its CSS code not HTML. The HTML attributes were deprecated in HTML5, nothing to do with CSS if you know what I mean. Commented Oct 14, 2012 at 9:56

2 Answers 2

98

The width attribute of <td> is deprecated in HTML 5.

Use CSS. e.g.

 <td style="width:100px"> 

in detail, like this:

<table > <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td style="width:70%">January</td> <td style="width:30%">$100</td> </tr> <tr> <td>February</td> <td>$80</td> </tr> </table> 
Sign up to request clarification or add additional context in comments.

5 Comments

What if you need to exceed the width of the page? For example the width of the page is 2000 and your cell needs to be 5000 like: <td style="width:5000px">January</td>
@IgorKrupitsky put the table inside t div that has css: overflow-x: scroll; You will then get a horizontal scrollbar
doesn't seem to work for a table with more columns, and where the columns have varying amounts of data in them
"The width attribute of <td> is deprecated in HTML 5." - it was actually already deprecated in HTML 4; see w3.org/TR/html401/struct/tables.html#edef-TH.
Its deprecated but I noticed it still working - at least in Chrome 64. Why?
17

Following width worked well in HTML5: -

<table > <tr> <th style="min-width:120px">Month</th> <th style="min-width:60px">Savings</th> </tr> <tr> <td>January</td> <td>$100</td> </tr> <tr> <td>February</td> <td>$80</td> </tr> </table> 

Please note that

  • TD tag is without CSS style.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.