Web Basics (HTML5) Classbook Lesson03 Tables
Web Basics (HTML5) Classbook Lesson03 Tables
Web Basics –
HTML5
Lesson 3: Tables
Page 03-1
Web Basics – HTML5 Tables
Lesson Objectives
Page 03-2
Web Basics – HTML5 Tables
3.1:Tables
Creating Tables
➢Table contains data in the format of rows and columns.
➢For an example, department information’s are displayed in the
tabular format as shown below
Tables
Tables are defined with the <table> tag. A table is divided into
rows (using <tr>), and each row is divided into data cells
(using <td>). Letters td stand for "table data," which is the
content of a data cell. A data cell can contain text, images,
lists, paragraphs, forms, horizontal rules, tables, etc.
Page 03-3
Web Basics – HTML5 Tables
3.1:Tables
Creating Tables
➢An HTML table can be created using <table> elements
• <table>
• Define an HTML table
• Other elements like <tr>, <caption>,.. can be nested inside <table> element
Header
➢An HTML table has two kinds of cells
• Header Cells Cells
• <th>
• Defines a table header
➢Standard Cells
• <tr>
• Defines a table row
• A row can have one or more <td> or <th> elements
➢<td>
• Defines a table cell data Standard
Cells
Page 03-4
Web Basics – HTML5 Tables
3.1:Tables
Creating Tables
➢Syntax
<table>
<tr>
<th>Column1 Header</th>
<th>Column2 Header</th>
</tr>
<tr>
<td>Cell 1,1</td>
<td>Cell 1,2</td>
</tr>
<tr>
<td>Cell 2,1</td>
<td>Cell 2,2</td>
</tr>
</table>
Page 03-5
Web Basics – HTML5 Tables
3.1:Tables
Creating Tables
➢Some more elements which can be used while creating tables are:
• <thead>
• Group header content in an HTML table
• <tbody>
• Group the body content in an HTML table
• <tfoot>
• Group footer content in an HTML table
• <caption>
• Defines a caption for the table
• <caption> element should follow with <table> element immediately.
• <caption> element value will be center aligned and displayed above the table
The table also has a few more tags to layout your data.
The <thead> tag is used to group the header content in an
HTML table.The <thead> element should be used in
conjunction with the <tbody> and <tfoot> elements.
The <tbody> element is used to group the body content in an
HTML table and the <tfoot> element is used to group the
footer content in an HTML table.
<tfoot> must appear before <tbody> within a table, so that a
browser can render the foot before receiving all the rows of
data.
Page 03-6
Web Basics – HTML5 Tables
3.1:Tables
Creating Tables
➢Syntax
Table Caption:
• The <caption> tag defines a table caption.
• The <caption> tag must be inserted immediately
after the <table> tag.
• You can specify only one caption per table. Usually
the caption will be centered above the table.
Table Headers:
The <th> tag defines a header cell in an HTML table.
Page 03-7
Web Basics – HTML5 Tables
3.1:Tables
Creating Tables
➢Syntax
<table>
<thead>
<tr><td>.....</td></tr>
</thead>
<tfoot>
<tr><td>.....</td></tr>
</tfoot>
<tbody>
<tr><td>....</td></tr>
<tbody>
</table>
Page 03-8
Web Basics – HTML5 Tables
3.1:Tables
Page 03-9
Web Basics – HTML5 Tables
3.1:Tables
Creating Tables
➢Tableheading.html
Page 03-10
Web Basics – HTML5 Tables
3.1:Tables
<table>
<tr> <th>Zone</th> <th> State </th> </tr>
<tr> <td>South</td>
<td><table>
<tr> <th>Name</th> <th>Capital City</th> </tr>
<tr> <td>Karnataka</td> <td>Bangalore</td> </tr>
<tr> <td>Tamilnadu</td> <td>Chennai</td> </tr>
<tr> <td>Andhra Pradesh</td> <td>Hyderabad</td>
</tr>
</table></td></tr>
</table>
The table also has a few more tags to layout your data.
The <thead> tag is used to group the header content in an
HTML table.The <thead> element should be used in
conjunction with the <tbody> and <tfoot> elements.
The <tbody> element is used to group the body content in an
HTML table and the <tfoot> element is used to group the
footer content in an HTML table.
<tfoot> must appear before <tbody> within a table, so that a
browser can render the foot before receiving all the rows of
data.
Page 03-11
Web Basics – HTML5 Tables
3.1:Tables
Demo
➢tabnest4.htm
Page 03-12
Web Basics – HTML5 Tables
Table Formatting
➢Cell Spanning
• Table cells can span across more than one column or row.
• Types of cell spanning
• Row spanning
• Column spanning
Cell Spanning:
There are two types of cell spanning. Row and column
spanning.
Page 03-13
Web Basics – HTML5 Tables
<table>
<tr>
<th rowspan=m>Multiple Column Header</th>
<th colspan=n>Multiple Row Header</th>
</tr>
</table>
colspan="number of columns" ~
By default, the number of columns in a table is defined by
the number of table data cells appearing in the table row that
contains the most data. You would, typically place the same
number of data cells in each table row. If a table row does not
contain the requisite number of table cells, then it will
essentially be in 'error' and will be displayed with a missing
cell.
rowspan="number of rows" ~
Rowspan attribute works just like the colspan attribute
except that you may find the situation a little more difficult to
visualize when working with the source code. But once again
the principle is the same. By using the rowspan attribute, you
can force a table cell to span the number of rows specified by
the respective value.
Page 03-14
Web Basics – HTML5 Tables
Page 03-15
Web Basics – HTML5 Tables
Grouping of Columns
➢ <colgroup> tag specifies a group of one or more columns in a
table for formatting
➢ The <col> tag specifies column properties for each column within
a <colgroup> element.
➢ Use <colgroup> and <col> tags to group columns with common
properties like
• Span attribute :
• Identifies number of columns in the current group.
• Default value is 1
• Provide span attribute and omit <col> tag
➢ Example for grouping 3 columns and applying background color as
green
<table>
<colgroup span=“3” style=“background-color:green”> </colgroup>
<col>
<col>
<tr> table contents…… </tr>
</table>
colspan="number of columns" ~
By default, the number of columns in a table is defined by
the number of table data cells appearing in the table row that
contains the most data. You would, typically place the same
number of data cells in each table row. If a table row does not
contain the requisite number of table cells, then it will
essentially be in 'error' and will be displayed with a missing
cell.
rowspan="number of rows" ~
Rowspan attribute works just like the colspan attribute
except that you may find the situation a little more difficult to
visualize when working with the source code. But once again
the principle is the same. By using the rowspan attribute, you
can force a table cell to span the number of rows specified by
the respective value.
Page 03-16
Web Basics – HTML5 Tables
Demo
➢ tabcol3.htm
Page 03-17
Web Basics – HTML5 Tables
Lab
➢ Lab 2
Page 03-18
Web Basics – HTML5 Tables
Lesson Summary
Page 03-19
Web Basics – HTML5 Tables
Review - Questions
Page 03-20