We can create a table in html by using <htmt></htmt> tag.
with in table tag we use <tr> to create new table row.
inside tr we use <td> tag to specify data value.
to provide table header <th> tag is used
One table can contain multiple table rows and each row can contain multiple table data.
Syntax
| ... | ... |
|---|---|
| ..... | ...... |
| ..... | ...... |
<th> is optional it is used to provide HTML Table with Header
Example
| Sr No | Name | City |
|---|---|---|
| 1 | Manish | Bhilai |
| 1 | Mohan | Bhopal |
| 1 | Ram | Banglore |
For providing data heading we use <th> tag
HTML Table with border
In above table we have not provided table border to provide HTML table with border we can use border attribute with border tag as below
table border=" 1|0"
0 specify no border around the table
1 specify border around the table
HTML Border attribute in not support by HTML 5.
Insted of border attribute use CSS.
| User Name | Mailid |
|---|---|
| Ram | [email protected] |
| Mohan | [email protected] |
| Shyam | [email protected] |
| User Name | Mailid |
|---|---|
| Ram | [email protected] |
| Mohan | [email protected] |
| Shyam | [email protected] |
HTML Table border with CSS
| Name | Mailid |
|---|---|
| Ram | [email protected] |
| Mohan | [email protected] |
| Shyam | [email protected] |
HTML Table With Caption
To provide table caption <caption> tag is used is should be used below the <table> tag
| User Name | Mailid |
|---|---|
| Ram | [email protected] |
| Mohan | [email protected] |
| Shyam | [email protected] |
| User Name | Mailid |
|---|---|
| Ram | [email protected] |
| Mohan | [email protected] |
| Shyam | [email protected] |
HTML Table Grouping Tag
<thead>, <tbody> and <tfooter> tags are used for grouping table rows <thead> is used to group table header
<tbody> is used to group table body
<tfooter is used to group table footer
| Sr no | Item | Quantity | Price |
|---|---|---|---|
| 1 | Cack | 1 | 150 |
| 2 | Toast | 1 | 80 |
| 3 | Biscuit | 2 | 50 |
| Sum | $180 |
Q Which tag allows you to add a row in a table?
tr rag allows us to add a row in a table
Q Can a data cell contain images in html
yes We can include images in HTML data cell
Q what is the use of “border ” attribute of table tag?
“border ” attribute of table tag is used to set table border