Basic Table Elements and Attributes in HTML: Part 1
Table of Content:
We already discuss about these below attributes
- The
alignAttribute - The
bgcolorAttribute - The
borderAttribute
The <table> Element Creates a Table
- The
alignAttribute - The
bgcolorAttribute - The
borderAttribute - The
cellpaddingAttribute - The
cellspacingAttribute - The
dirAttribute - The
frameAttribute - The
rulesAttribute - The
summaryAttribute - The
widthAttribute
The <tr> Element Contains Table Rows
- The
alignAttribute - The
bgcolorAttribute - The
charAttribute - The
charoffAttribute - The
valignAttribute
The <td> and <th> Elements Represent Table Cells
- The
abbrAttribute - The
alignAttribute - The
axisAttribute - The
bgcolorAttribute - The
charAttribute - The
charoffAttribute - The
colspanAttribute - The
headersAttribute - The
heightAttribute - The
nowrapAttribute - The
rowspanAttribute - The
scopeAttribute - The
valignAttribute - The
widthAttribute
- Adding a
<caption>to a Table - Spanning Columns Using the
colspanAttribute - Spanning Rows Using the
rowspanAttribute - Splitting Up Tables Using a Head, Body, and Foot
- Grouping Columns Using the
<colgroup>Element - Columns Sharing Styles Using the
<col>Element - Nested Tables
The cellpadding Attribute
The cellpadding attribute is used to create a gap between the edges of a cell and its contents.
cellpadding="5" or cellpadding="2%"
This attribute has been replaced by the padding property in CSS.
HTML Code
| Month | Earning |
|---|---|
| January | $100 |
Live Preview
The cellspacing Attribute
The cellspacing attribute is used to create a space between the borders of each cell.
cellspacing="6" or cellspacing="2%"
HTML Code
| Month | Earnning |
|---|---|
| January | $100 |
Live Preview
The cellspacing attribute of <table> is not supported in HTML5.
The cellspacing attribute specifies the space, in pixels, between cells.
This attribute has been replaced by the margin property in CSS.
The dir Attribute
The dir attribute is used to set the base direction of text for display. It is essential for enabling HTML in right-to-left scripts such as Arabic, Hebrew, Syriac, and Thaana. Numerous different languages are written with these scripts, including Arabic, Hebrew, Pashto, Persian, Sindhi, Syriac, Dhivehi, Urdu, Yiddish, etc.
he dir attribute is supposed to indicate the direction of text that is used in the table. Possible values are ltr for left to right text and rtl for right to left
dir="rtl"
HTML Code
This is a example of dir="rtl"
| Month | Earnning |
|---|---|
| January | $100 |
Live Preview
The frame Attribute
The frame attribute was used to define the visible borders of a table. It is now deprecated and should no longer be used. frame , with greater control than the border attribute.
The following table shows the possible values for the frame attribute.
| Value | Purpose | Example |
| void | No outer border (the default) | <table frame="void"> |
| above | A border on the top only | <table frame="above"> |
| below | A border on the bottom only | <table frame="below"> |
| hsides | A border on the top and bottom | <table frame="hsides"> |
| lhs | A border on the left side of table | <table frame="lhs"> |
| rhs | A border on the right side of table | <table frame="rhs"> |
| vsides | A border on the left and right sides of table | <table frame="vsides"> |
| box | A border on all sides | <table frame="box"> |
| border | A border on all sides | <table frame="border"> |
Support for the frame attribute is not perfect across browsers, and its role has been replaced by the CSS
border property, which can give better results.
Now we will discuss by By this examples
| Name | Food |
|---|---|
| Jakir | Rasgola |
| Sabir | Masala Dosa |
| Sourav | Biryani |
| Rohan | Chole Batura |
| Rumman | Birayani |
Let's start
Example: 1 <table frame="void">
No outer border (the default)
| Name | Food |
|---|---|
| Jakir | Rasgola |
| Sabir | Masala Dosa |
| Sourav | Biryani |
| Rohan | Chole Batura |
| Rumman | Birayani |
Live Preview
Example: 2 <table frame="above">
A border on the top only.
| Name | Food |
|---|---|
| Jakir | Rasgola |
| Sabir | Masala Dosa |
| Sourav | Biryani |
| Rohan | Chole Batura |
| Rumman | Birayani |
Live Preview
Example: 3 <table frame="below">
A border on the bottom only.
| Name | Food |
|---|---|
| Jakir | Rasgola |
| Sabir | Masala Dosa |
| Sourav | Biryani |
| Rohan | Chole Batura |
| Rumman | Birayani |
Live Preview
Example: 4 <table frame="hsides">
A border on the top and bottom.
| Name | Food |
|---|---|
| Jakir | Rasgola |
| Sabir | Masala Dosa |
| Sourav | Biryani |
| Rohan | Chole Batura |
| Rumman | Birayani |
Live Preview
Example: 5 <table frame="lhs">
A border on the left side of table.
| Name | Food |
|---|---|
| Jakir | Rasgola |
| Sabir | Masala Dosa |
| Sourav | Biryani |
| Rohan | Chole Batura |
| Rumman | Birayani |
Live Preview
Example: 6 <table frame="rhs">
A border on the right side of table.
| Name | Food |
|---|---|
| Jakir | Rasgola |
| Sabir | Masala Dosa |
| Sourav | Biryani |
| Rohan | Chole Batura |
| Rumman | Birayani |
Live Preview
Example: 7 <table frame="vsides">
A border on the left and right sides of table.
| Name | Food |
|---|---|
| Jakir | Rasgola |
| Sabir | Masala Dosa |
| Sourav | Biryani |
| Rohan | Chole Batura |
| Rumman | Birayani |
Live Preview
Example: 8 <table frame="box">
A border on all side
| Name | Food |
|---|---|
| Jakir | Rasgola |
| Sabir | Masala Dosa |
| Sourav | Biryani |
| Rohan | Chole Batura |
| Rumman | Birayani |
Live Preview
Example: 9 <table frame="border">
A border on all sides
| Name | Food |
|---|---|
| Jakir | Rasgola |
| Sabir | Masala Dosa |
| Sourav | Biryani |
| Rohan | Chole Batura |
| Rumman | Birayani |
Live Preview
Example:
Another example with mix of different attribute
| Name | Food |
|---|---|
| Jakir | Rasgola |
| Sabir | Masala Dosa |
| Sourav | Biryani |
| Rohan | Chole Batura |
| Rumman | Birayani |
Live Preview
- Question 1: Do <tr> tags always need to come at the start of a row or column?
- Question 2: What is the relationship between the border and rule attributes?
- Question 3: What happens if the number of values in the rows or cols attribute doesn