What is a Table?

// Quick Answer
  • A table is used to organize data into rows and columns.
  • HTML tables are created using the <table> element.
  • Tables are useful for displaying schedules, prices, reports, and comparisons.
  • HTML tables use rows (<tr>), headers (<th>), and cells (<td>).
  • Tables should be used for data, not page layout.

What is a Table?

A table is a structure used to organize information into rows and columns. In HTML, tables help display structured data clearly and neatly.

You can think of a table like a spreadsheet or school marksheet โ€” information is arranged in cells so it is easy to read and compare.

๐Ÿ’ก In simple terms

A table is like a grid that stores information in rows and columns.

What is an HTML table?

An HTML table is created using the <table> element. Inside the table:

  • <tr> creates a row
  • <th> creates a header cell
  • <td> creates a normal data cell
index.html
<table>
  <tr>
    <th>Name</th>
    <th>Age</th>
  </tr>

  <tr>
    <td>Alex</td>
    <td>21</td>
  </tr>

  <tr>
    <td>Sarah</td>
    <td>19</td>
  </tr>
</table>

How do tables work?

Tables organize information horizontally and vertically:

  • Rows run across the table.
  • Columns run down the table.
  • Cells hold the actual data.

Each row usually represents one record, while columns represent categories of information.

๐Ÿ“Œ Real-world examples

Tables are commonly used for timetables, pricing charts, scoreboards, invoices, analytics, and product comparisons.

What are tables used for?

HTML tables are useful whenever structured data needs to be displayed clearly.

  • ๐Ÿ“… Schedules and timetables
  • ๐Ÿ’ฐ Pricing tables
  • ๐Ÿ“Š Reports and statistics
  • ๐Ÿงพ Invoices and bills
  • ๐Ÿ† Scoreboards and rankings

Important: tables are not for layout

In the early days of the web, developers used tables to build page layouts. This is now considered bad practice.

Modern layouts should use:

  • CSS Flexbox
  • CSS Grid
โš ๏ธ Best practice

Use tables only for displaying tabular data โ€” not for designing page layouts.

Basic table styling with CSS

CSS can make tables easier to read and visually appealing.

style.css
table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border: 1px solid #ccc;
  padding: 12px;
}

th {
  background: #f5f5f5;
}

Summary

A table is a way to organize information into rows and columns. In HTML, tables are created using the <table> element and are ideal for displaying structured data like schedules, reports, and comparisons.

Tables are an important part of HTML, but they should only be used for data presentation โ€” not page layouts.