How to set table width in HTML?

HTMLWeb DevelopmentFront End Technology

To set the table width in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property width. HTML5 do not support the width attribute of <table>, so the CSS property width is used with the style attribute to set table width.

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.

Example

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

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         th, td {
            border: 1px solid black;
         }
      </style>
   </head>

   <body>
      <h1>Programming Languages</h1>
      <table style="width:100px; border: 1px solid black">
         <tr>
            <th>Language</th>
            <th>Release Year</th>
         </tr>
         <tr>
            <td>Java</td>
            <td>1995</td>
         </tr>
         <tr>
            <td>Pascal</td>
            <td>1970</td>
         </tr>
      </table>
   </body>
</html>
raja
Published on 01-Feb-2018 06:53:03
Advertisements