Tables in HTML

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

Overview

To organise data into rows and columns Tables in HTML are used. Tables are used to organise information such as images, text, and links. Suppose you want to show data of a student and just writing in a text format will be very untidy therefore using tables will become tedious and understandable for the user.

HTML Tables

Tables in HTML are a collection of data organised in rows and columns, or a more complicated form tables are commonly used in data analysis, research, and communication. Tables can be used for a variety of purposes like showing text and numerical data. It is used in a tabular form layout to differentiate between two or more topics. Databases are built using tables.

To create a Table in HTML <table> tag is used which is the main container of the table.

Syntax

Example

Output

NameCourseApplication Number
AlianaB.Tech CSE17218
MariaFashion Tech17219
SarahJournalism17272
ElenaMBA17291

We will be looking at <tr>, <th> and <td> tags in this article.

Table Cells

The <td> tag is defined as a cell in Tables in HTML which contain data.

Syntax

Example

Output

Sarah20B.Tech

From the following output, we can see that a table row is created containing three table cells which are created in a row using <td> tag.

Table Rows

To arrange data horizontally in different table cells are called table rows.

To create a table row we use <tr> tag.

Syntax

Example

Output

NameAgeCourse
Sarah20B.Tech

From the output, we can say that 2 rows are created with 3 columns using data cells i.e., the <td> tag.

Table Header

To represent a table cell we use table headers. Tables in HTML can have headers horizontally as well as vertically.

To create a table header <th> tag is used.

Syntax

Here is an example of horizontal and vertical headers, where we will be creating a simple time-table.

Example

Output

Time/DaysMondayTuesday
8:00amPythonJava
12 noonSpanishEnglish
3:00 PMData StructuresNetworking

As we can see table headers are added vertically as well as horizontally to do so we have added <th> tag in every <tr> tag.

HTML Table Tags

These are the different HTML tags used in a table.

TagsDescription
<table>Used to create a table.
<tr>Used to create table rows.
<td>Used to create table data/cells.
<th>Used to create table header.
<caption>A table caption is defined.
<colgroup>It is used to format a group of one or more columns in a table.
<col>Used with the <colgroup> element to define column characteristics for each column.
<tbody>The table body is grouped together using it.
<thead>Table head is grouped together using this tag.
<tfooter>Footer content is grouped together using this tag.

Example of Tables in HTML

As we have gone through the basics of Tables in HTML, let's create a simple table that will include data of a students Marksheet.

Example

Output

NamePhysicsChemistryMathsTotal Marks
Abhishek608759100
Anirudh638045100
Aditi554086100
Prakarsh649085100

A table is created which contains five rows and the first row contains the heading part only which is created using <th> tag.

Supported Browsers

Tables in HTML are supported by the following browsers -

  • Chrome
  • Microsoft Edge
  • Safari
  • Firefox
  • Internet explorer
  • Opera

Conclusion

  • Data is organised into rows and columns using HTML tables. Tables are used to organise data like photographs, text, and hyperlinks.
  • <tr> tag is used to create table rows, <th> tag is used to define table headers while <td> tag is used for table data/cells.