learn2kode.in

HTML – Tables

1. HTML Tables

HTML tables allow you to display data in rows and columns.

Basic Structure

Tag Meaning
<table> Creates a table
<tr> Table row
<td> Table data/cell
<th> Table header cell

Example

<table border="1">
  <tr>
    <td>Row 1, Cell 1</td>
    <td>Row 1, Cell 2</td>
  </tr>
  <tr>
    <td>Row 2, Cell 1</td>
    <td>Row 2, Cell 2</td>
  </tr>
</table>

HTML - Tables

Tables can include borders, spacing, padding, and alignment.

Common Table Attributes

Attribute Description
border Adds a border to the table
cellpadding Space inside each cell
cellspacing Space between cells
width Width of table
align Aligns table (deprecated but works)

Example

<table border="1" cellpadding="10" cellspacing="5" width="50%">
  <tr>
    <td>A</td>
    <td>B</td>
  </tr>
</table>