Computer >> Computer tutorials >  >> Programming >> HTML

How to set cell width and height in HTML?


To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn’t supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively.

Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML <style> tag or external style sheet.

How to set cell width and height in HTML?

You can try to run the following code to set height and width to a table cell in HTML. We’re also using the <style> tag and the style attribute to style the table

Example

<!DOCTYPE html>
<html>
   <head>
      <style>
         table, th, td {
            border: 1px solid black;
         }
      </style>
   </head>
   
   <body>
      <h1>Tutorial</h1>
      <table>
         <tr>
            <th>Language</th>
            <th>Lessons</th>
         </tr>
         <tr>
            <td style="height:100px;width:100px">Java</td>
            <td style="height:100px;width:100px">50</td>
         </tr>
         <tr>
            <td>Ruby</td>
            <td>40</td>
         </tr>
      </table>
   </body>
</html>