HTML Tables - SwatiMaurya08/html-notes GitHub Wiki
The HTML tables allow web authors to arrange data like text, images, links, other tables, etc. into rows and columns of cells.
The HTML tables are created using the <table>
tag in which the <tr>
tag is used to create table rows and <td>
tag is used to create data cells. The elements under <td>
are regular and left aligned by default.
Here, the border is an attribute of
tag and it is used to put a border across all the cells. If you do not need a border, then you can use border = "0".Table heading can be defined using <th>
tag. This tag will be put to replace <td>
tag, which is used to represent actual data cell. Headings, which are defined in <th>
tag are centered and bold by default.
There are two attributes called cellpadding and cellspacing which you will use to adjust the white space in your table cells. The cellspacing attribute defines space between table cells, while cellpadding represents the distance between cell borders and the content within a cell.
You will use colspan attribute if you want to merge two or more columns into a single column. Similar way you will use rowspan if you want to merge two or more rows.
You can set table background using one of the following two ways −
bgcolor attribute − You can set background color for whole table or just for one cell.
background attribute − You can set background image for whole table or just for one cell.
You can also set border color also using bordercolor attribute.
Note − The bgcolor, background, and bordercolor attributes deprecated in HTML5. Do not use these attributes.
You can set a table width and height using width and height attributes. You can specify table width or height in terms of pixels or in terms of percentage of available screen area.
The caption tag will serve as a title or explanation for the table and it shows up at the top of the table. This tag is deprecated in newer version of HTML/XHTML.
Tables can be divided into three portions − a header, a body, and a foot. The head and foot are rather similar to headers and footers in a word-processed document that remain the same for every page, while the body is the main content holder of the table.
The three elements for separating the head, body, and foot of a table are −
-
<thead>
− to create a separate table header. -
<tbody>
− to indicate the main body of the table. -
<tfoot>
− to create a separate table footer.
A table may contain several <tbody>
elements to indicate different pages or groups of data. But it is notable that <thead>
and <tfoot>
tags should appear before <tbody>
.
You can use one table inside another table. Not only tables you can use almost all the tags inside table data tag <td>
.