Basic Table Elements and Attributes part 4 (The <td> and <th> Elements)
Table of Content:
The td and th Elements
The <td> and <th> Elements Represent Table Cells.
Remember By default, the contents of a <th> element are usually displayed in a bold font, horizontally aligned in the center of the cell. The content of a <td> element, meanwhile, will usually be displayed left - aligned and not in bold (unless otherwise indicated by CSS or another element).
Now we will discuss about the below attributes.
- The
abbr
Attribute - The
align
Attribute - The
axis
Attribute - The
bgcolor
Attribute - The
char
Attribute - The
charoff
Attribute - The
colspan
Attribute - The
headers
Attribute - The
height
Attribute - The
nowrap
Attribute - The
rowspan
Attribute - The
scope
Attribute - The
valign
Attribute - The
width
Attribute
The abbr
Attribute
The pPurpose of the HTML abbr attribute is to specify the abbreviation for a table header cell.
Type of value of HTML abbr attribute is text.There is no default value of HTML abbr attribute.
<td abbr="value" >.....</td> <th abbr="value" >.....</th>
Example of HTML abbr attribute with td
UK | Capital is London. |
USA | Capital is Washington, D.C. |
Live Preview
Example of HTML abbr attribute with th
Country | Capital of the state |
---|---|
UK | Capital is London. |
USA | Capital is Washington, D.C. |
Live Preview
The align
Attribute
The align attribute sets the horizontal alignment for the content of the cell.
HTML align attribute supports col, colgroup, tbody, td, tfoot, th, thead, tr elements. Usage of align attribute for any other HTML elements is deprecated. You must use CSS for those.
align = "alignment"
The possible values for the align attribute are left, right, center, justify,
and char, each of which
was described earlier in "The <tr> Element Contains Table Rows" section.
Name | Description |
---|---|
left | Left align data, left justify text. |
center | Center align data, center justify text. |
right | Right align data, right justify text. |
justify | Double justify text. |
char | If used, text is aligned around a specific character. |
Example 1: align="left"
Student Code | % of marks |
---|---|
S001 | 86.79 |
S002 | 78.98 |
S003 | 83.59 |
Live Preview
Example 2: align="center"
Student Code | % of marks |
---|---|
S001 | 86.79 |
S002 | 78.98 |
S003 | 83.59 |
Live Preview
Example 3: align="right"
Student Code | % of marks |
---|---|
S001 | 86.79 |
S002 | 78.98 |
S003 | 83.59 |
Live Preview
Example 4: align="justify"
Student Code | % of marks |
---|---|
S001 | 86.79 |
S002 | 78.98 |
S003 | 83.59 |
Live Preview
Example 5: align="char"
Student Code | % of marks |
---|---|
S001 | 86.79 |
S002 | 78.98 |
S003 | 83.59 |
Live Preview
The axis
Attribute
The purpose of the HTML axis attribute is to specify a comma-separated list of category names for a table cell or table header cell.
axis = "heavy, old, valuable"
Rather than having a visual formatting effect, this attribute allows you to preserve data, which then may be used programmatically, such as querying for all cells belonging to a certain category.
HTML axis attribute supports td and th elements.
Country | Capital of the Country |
---|---|
USA | Washington,D.C. |
UK | London |
Live Preview
The bgcolor
Attribute
The bgcolor attribute sets the background color for the cell. The value of this attribute should be either a color name or a hex code
bgcolor = "red"
Country | Capital of the Country |
---|---|
USA | Washington,D.C. |
UK | London |
Live Preview
The char
Attribute
Same as the previous chapter.
The charoff
Attribute
Same as the previous chapter.
The colspan
Attribute
The purpose of the HTML colspan attribute is to define the number of columns spanned by an individual column definition.
HTML colspan attribute supports td and th elements
colspan = "2"
The value of the attribute specifies how many columns of the table a cell will span across.
Development | |
---|---|
Em001 | $1500.00 |
Em002 | $1550.00 |
Em003 | $1700.00 |
Total : $4750.00 | |
Marketing | |
Em005 | $1500.00 |
Em006 | $1500.00 |
Em006 | $1500.00 |
Total : $4500.00 |
Live Preview
The headers
Attribute
The purpose of the HTML headers attribute is to specify a space-separated list of identifiers for table header cells. HTML headers attribute supports td and th elements.
headers = "income q1"
Code | Salary |
---|---|
EM001 | $1600.00 |
The main purpose of this attribute is to support voice browsers. When a table is being read to you, it can be hard to keep track of which row and column you are on; therefore, the header attribute is used to remind users which row and column the current cell's data belongs to.
Live Preview
The height
Attribute
The height attribute allows you to specify the height of a cell in pixels, or as a percentage of the available space:
height ="30" or height="20%"
It has been replaced by the CSS height property.
Code | Salary |
---|---|
EM001 | $1600.00 |
The main purpose of this attribute is to support voice browsers. When a table is being read to you, it can be hard to keep track of which row and column you are on; therefore, the header attribute is used to remind users which row and column the current cell's data belongs to.
Live Preview
The nowrap
Attribute (Deprecated)
Not be allowed in XHTML, HTML 5
nowrap = "nowrap"
The nowrap attribute is used to stop text from wrapping onto a new line within a cell. You would use nowrap only when the text really would not make sense if it were allowed to wrap onto the next line (for example, a line of code that would not work if it were spread across two lines).