HTML Table Attributes


HTML offers multiple attributes that can be set on <table>, <tr>, <th>, and <td> elements to customize tables' presentation and functionality.

 


Table-Level Attributes

Attribute Description
border Sets the width of the border around the table and cells
cellpadding Sets space between cell content and cell border
cellspacing Sets space between adjacent cells
width Specifies width of the table (in px or %)
height Specifies height of the table
align Aligns the table (left, center, right – deprecated in HTML5)

<table border="1" cellpadding="10" cellspacing="5" width="80%" height="200">
  <tr>
    <th>Name</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>Alice</td>
    <td>25</td>
  </tr>
</table> 

Cell-Level Attributes

Attribute Description
colspan Makes a cell span multiple columns
rowspan Makes a cell span multiple rows
align Aligns text horizontally (left, center, right)
valign Aligns text vertically (top, middle, bottom)
width, height Sets size of individual cells

Example with colspan and rowspan

<table border="1">
  <tr>
    <th>Name</th>
    <th colspan="2">Details</th>
  </tr>
  <tr>
    <td rowspan="2">Alice</td>
    <td>Age</td>
    <td>25</td>
  </tr>
  <tr>
    <td>City</td>
    <td>New York</td>
  </tr>
</table> 

notepad
  • Use CSS instead of deprecated attributes like align, bgcolor, bordercolor
  • Always use border-collapse: collapse in CSS to avoid double borders
  • Keep your table accessible by using <th> for headings



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.