Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

html

How to use the 'table' element in HTML

Dian Us Suqlain

Table is one of the elements in HTML that we can use to create tables in our web pages.

The table element

An HTML table element consists of some tags and attributes necessary to build a table. Those tags are as follows:

  • <td>: defines a standard data cell in an HTML table.
  • <tr>: defines a row in an HTML table.
  • <th>: defines a header cell in an HTML table.
The <table>, <tr>, <th> and <td> tags.

Syntax

As shown in the illustration above, a <table> tag uses multiple elements to create a simple table in HTML. The following syntax shows how to create a table with three rows and one element in each row.

<table>
  <tr>
    <th>....</th>
  </tr>
  <tr>
    <td>...</td>
  </tr>
  <tr>
    <td>...</td>
  </tr>
</table>

Code

Consider the following example code that demonstrates how to create a table in HTML.

Explanation

In the implementation above, we have made three data entries using the <td> (John, Jessica, and Billy), along with their respective ages.

The <th> tag creates headings for Name and Age. Both the <th> and <td> tags are included inside the <tr> tag to group them in a single row.

We use CSSCascade Style Sheets to make a border around the table entries so that it will look like an actual table.

RELATED TAGS

html

CONTRIBUTOR

Dian Us Suqlain
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring