🏠 Home / Hub

🌐 HTML Lesson 04 — Tables

← Back to HTML Menu

1. Basic Table Structure

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Age</th>
      <th>City</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Ko Min</td>
      <td>25</td>
      <td>Yangon</td>
    </tr>
    <tr>
      <td>Ma Aye</td>
      <td>22</td>
      <td>Mandalay</td>
    </tr>
  </tbody>
</table>
NameAgeCity
Ko Min25Yangon
Ma Aye22Mandalay
Table Tags:
<table> → Table container
<thead> → Header group
<tbody> → Body group
<tfoot> → Footer group
<tr> → Table Row
<th> → Header Cell (bold, center)
<td> → Data Cell

2. colspan & rowspan — Cell merge

<!-- colspan: အလျားတိုး -->
<table border="1">
  <tr>
    <th colspan="3">
      Full Name
    </th>
  </tr>
  <tr>
    <td>Title</td>
    <td>First</td>
    <td>Last</td>
  </tr>
</table>

<!-- rowspan: အမြင့်တိုး -->
<table border="1">
  <tr>
    <td rowspan="2">
      Merged
    </td>
    <td>Row 1</td>
  </tr>
  <tr>
    <td>Row 2</td>
  </tr>
</table>

colspan example:

Full Name
Mr/MrsFirst NameLast Name
MrMinAung

rowspan example:

Merged
Cell
Row 1 Col 2
Row 2 Col 2

3. Full Table (thead + tbody + tfoot)

<table>
  <caption>💰 Monthly Sales Report</caption>
  <thead>
    <tr><th>Product</th><th>Qty</th><th>Price</th><th>Total</th></tr>
  </thead>
  <tbody>
    <tr><td>Apple</td><td>10</td><td>500</td><td>5,000</td></tr>
    <tr><td>Banana</td><td>5</td><td>300</td><td>1,500</td></tr>
  </tbody>
  <tfoot>
    <tr><td colspan="3"><strong>Grand Total</strong></td><td>6,500</td></tr>
  </tfoot>
</table>
💰 Monthly Sales Report
ProductQtyPrice (Ks)Total (Ks)
Apple105005,000
Banana53001,500
Orange84003,200
Grand Total9,700

4. Table Styling (CSS)

table {
  border-collapse: collapse;  /* border gaps ဖျက် */
  width: 100%;
}
th, td {
  border: 1px solid #ddd;
  padding: 8px 12px;
  text-align: left;
}
th {
  background-color: #2c3e50;
  color: white;
}
tr:nth-child(even) {
  background-color: #f8f9fa;  /* Zebra stripes */
}
tr:hover {
  background-color: #fff3ee;  /* Hover highlight */
}
border-collapse: collapse သုံးပါ — မသုံးရင် cell တိုင်းမှာ double border ဖြစ်မယ်

5. Dynamic Table Builder

← HTML 03  |  Next: HTML Lesson 05 → Forms

📌 Study Checklist