Various tags are used for creating a table in a web page and those tags which are used for creation, are discussed herewith
<table> tag – A table is created by using <table> tag. In the <table> element the table is built row by row. A row is present in a <tr> tag, which stands for ‘table row’. And each cell is then written inside the row element using a <td> tag, which stands for ‘table data’. Each cell must have a <td> or a <th> tag to display correctly. An example is shown
HTML code
<table border=”1″> <tr> <td>Row 1, Column 1</td> <td>Row 1, Column 2</td> </tr> <tr> <td>Row 2, Column 1</td> <td>Row 2, Column 2</td> </tr> </table> |
Browser output |
<tr> tag – It is used to contain each row in a table. Information appearing in it appears on the same row.
<td> tag – Every cell in a table is given by a <td> tag for cells having data or a <th> tag for cells containing table headings. The content of a <td> element, are usually displayed left – aligned. The <td> tag’s set of attributes applies to that one cell carrying it.
<th> tag – Heading for a table can be defined using <th> tag. It replaces the <td> tag in the top row of the table which is usually used to represent table heading. It can also be used else where in the table for emphasis.
HTML code
<table border=”1″> <tr> <th>Heading 1</th> <th>Heading 2</th> </tr> <tr> <td>Cell 1</td> <td>Cell 2</td> </tr> </table> |
Browser output |