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.
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
<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.
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
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.
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.