HTML/HTML Components

HTML Tables (with Attributes)

Updated on January 6, 2026
1 min read

What is an HTML Table?

An HTML table is used to display data in rows and columns, just like an Excel sheet.

Used for:

  • Student data
  • Marks
  • Product lists
  • Reports

Basic Table Structure

<table>
  <tr>
    <th>Name</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>Rahul</td>
    <td>20</td>
  </tr>
</table>

Table Attributes

1. border

<table border="1">

Shows table border

2. cellpadding

<table cellpadding="10">

Space inside cells

3. cellspacing

<table cellspacing="5">

Space between cells

4. width

<table width="50%">

5. align

<table align="center">

Attributes for <tr>, <th>, <td>

align

<td align="center">20</td>

colspan (Merge columns)

<td colspan="2">Total</td>

rowspan (Merge rows)

<td rowspan="2">Name</td>

Complete Example

<table border="1" cellpadding="10" cellspacing="0" width="60%" align="center">
  <tr>
    <th>Name</th>
    <th>Marks</th>
  </tr>
  <tr>
    <td>Ali</td>
    <td>85</td>
  </tr>
</table>

Important Notes 

  1. Use tables for data, not layout
  2. border, cellpadding are old-style (CSS preferred)
  3. <th> text is bold & centered
HTML Tables (with Attributes) | HTML | Learn Syntax