bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/HTML/HTML Foundations
HTML•HTML Foundations

HTML Tables

HTML tables allow web developers to arrange data into rows and columns.

Example

CompanyContactCountry
Alfreds FutterkisteMaria AndersGermany
Centro comercial MoctezumaFrancisco ChangMexico
Ernst HandelRoland MendelAustria
Island TradingHelen BennettUK
Laughing Bacchus WinecellarsYoshi TannamuriCanada
Magazzini Alimentari RiunitiGiovanni RovelliItaly

Define an HTML Table

A table in HTML consists of table cells inside rows and columns.

Example

Formatted code
<table>

<tr>
    <th>Company</th>

    <th>Contact</th>
    <th>Country</th>

</tr>

<tr>
    <td>Alfreds Futterkiste</td>

    <td>Maria
  Anders</td>
    <td>Germany</td>

</tr>
  <tr>
    <td>Centro
  comercial Moctezuma</td>

    <td>Francisco
  Chang</td>
    <td>Mexico</td>

  </tr>
</table>

Live preview

Table Cells

Each table cell is defined by a <td> and a </td> tag.

td stands for table data.

Everything between <td> and </td> is the content of a table cell.

Example

Formatted code
<table>

<tr>
    <td>Emil</td>

    <td>Tobias</td>
    <td>Linus</td>

</tr>
</table>

Live preview

Note

A table cell can contain all sorts of HTML elements: text, images, lists, links, other tables, etc.

Table Rows

Each table row starts with a <tr> and ends with a </tr> tag.

tr stands for table row.

Example

Formatted code
<table>

<tr>
    <td>Emil</td>

    <td>Tobias</td>
    <td>Linus</td>

</tr>

<tr>
    <td>16</td>

    <td>14</td>
    <td>10</td>

</tr>
</table>

Live preview

You can have as many rows as you like in a table; just make sure that the number of cells are the same in each row.

Note

There are times when a row can have less or more cells than another. You will learn about that in a later chapter.

Table Headers

Sometimes you want your cells to be table header cells. In those cases use the <th> tag instead of the <td> tag:

th stands for table header.

Example

Formatted code
<table>

<tr>
    <th>Person 1</th>

    <th>Person 2</th>
    <th>Person
  3</th>

</tr>

<tr>
    <td>Emil</td>

    <td>Tobias</td>
    <td>Linus</td>

</tr>

<tr>
    <td>16</td>

    <td>14</td>
    <td>10</td>

</tr>
</table>

Live preview

By default, the text in <th> elements are bold and centered, but you can change that with CSS.

HTML Table Tags

TagDescription
<table>Defines a table
<th>Defines a header cell in a table
<tr>Defines a row in a table
<td>Defines a cell in a table
<caption>Defines a table caption
<colgroup>Specifies a group of one or more columns in a table for formatting
<col>Specifies column properties for each column within a <colgroup> element
<thead>Groups the header content in a table
<tbody>Groups the body content in a table
<tfoot>Groups the footer content in a table

For a complete list of all available HTML tags, visit our HTML Tag Reference .

Styling Tables Filter Table Sort Table Responsive Table Zebra Striped Table

Previous

HTML Page Title

Next

HTML Table Borders

This chapter

Overview
56

Lessons

191m

Read time

1. HTML Tutorial2. HTML Introduction3. HTML Editors4. HTML Elements5. HTML Attributes6. HTML Headings7. HTML Paragraphs8. HTML Styles9. HTML Text Formatting10. HTML Comments11. HTML Colors12. HTML RGB and RGBA Colors13. HTML HEX Colors14. HTML HSL and HSLA Colors15. HTML Styles - CSS16. HTML Links17. HTML Links - Different Colors18. HTML Links - Create Bookmarks19. HTML Images20. HTML Image Maps21. HTML Background Images22. HTML <picture> Element23. HTML Favicon24. HTML Page Title25. HTML Tables26. HTML Table Borders27. HTML Table Sizes28. HTML Table Headers29. HTML Table Padding & Spacing30. HTML Table Colspan & Rowspan31. HTML Table Styling32. HTML Table Colgroup33. HTML Lists34. HTML Unordered Lists35. HTML Ordered Lists36. HTML Other Lists37. HTML Block and Inline Elements38. HTML Div Element39. HTML class Attribute40. HTML id Attribute41. HTML Buttons42. HTML Iframes43. HTML JavaScript44. HTML File Paths45. HTML - The Head Element46. HTML Layout Elements and Techniques47. HTML Responsive Web Design48. HTML Computer Code Elements49. HTML Semantic Elements50. HTML Style Guide51. HTML Entities52. HTML Symbols53. Using Emojis in HTML54. HTML Encoding (Character Sets)55. HTML Uniform Resource Locators56. HTML Versus XHTML

On this page

Define an HTML TableTable CellsTable RowsTable HeadersHTML Table Tags