Using Tables in HTML
Tables let you present data in a structured way using rows and columns. HTML tables are ideal for things like pricing lists, schedules, or statistics.
Table Structure
Tables start with the <table> tag. Rows are created using <tr>, headers with <th>, and cells with <td>.
Example: Rendered Table
Here’s an example of how a simple HTML table looks when rendered in the browser. This helps you visualize how the code appears.
| Item | Price | On Sale? |
|---|---|---|
| Apple | 0.2$ | Yes |
| Orange | 0.3$ | No |
| Banana | 0.1$ | Yes |
Special Cell Attributes
You can use colspan and rowspan on <td> elements to make a cell span multiple columns or rows.
html
<td colspan="2">Occupies two columns</td>html
<td rowspan="2">Occupies two rows</td>Semantic Table Elements
You can use <thead>, <tbody>, and <tfoot> tags to make your table structure more organized and easier to understand.
When to Use Tables
Use tables when you need to display structured data. Don’t use them for layout or design — modern CSS solutions are better suited for that.
✨ Ask Lara — your AI study partner
Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.
Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.
