Basic Table
In HTML, a table is used to display data in rows and columns. The <table> tag is used to create a table, and it contains rows (<tr>) and cells (<td> for data, <th> for headers).
Basic Table Structure
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
<tr>
<td>Alice</td>
<td>25</td>
<td>New York</td>
</tr>
<tr>
<td>Bob</td>
<td>30</td>
<td>London</td>
</tr>
</table>
Output:
Name | Age | City |
Alice | 25 | New York |
Bob | 30 | London |
Attributes of <table> in HTML
Attribute | Description | Example |
---|---|---|
border | Adds a border around the table & cells | <table border="1"> |
cellpadding | Space inside a cell between text & border | <table cellpadding="10"> |
cellspacing | Space between cells | <table cellspacing="5"> |
width | Defines the table width (in pixels or %) | <table width="80%"> |
height | Defines the table height (in pixels or %) | <table height="300px"> |
align | Aligns the table (left, center, right) | <table align="center"> |
bgcolor | Sets the background color of the table | <table bgcolor="lightblue"> |
Attributes of <tr> (Table Row)
Attribute | Description | Example |
align | Aligns text (left, center, right) | <tr align="center"> |
bgcolor | Sets background color for a row | <tr bgcolor="yellow"> |
valign | Aligns content vertically (top, middle, bottom) | <tr valign="top"> |
Attributes of <td> and <th> (Table Cells)
Attribute | Description | Example |
colspan | Merges multiple columns | <td colspan="2">Merged</td> |
rowspan | Merges multiple rows | <td rowspan="2">Merged</td> |
width | Sets the width of a cell | <td width="100px"> |
height | Sets the height of a cell | <td height="50px"> |
align | Aligns text (left, center, right) | <td align="center"> |
valign | Aligns content vertically (top, middle, bottom) | <td valign="top"> |
Qus. 1 : Which of the following tag is used to add rows in the table?
- <td> and </td>
- <th> and </th>
- <tr> and </tr>
- None of the above
- cell
- row
- step
- column
- <table><head><tfoot>
- <table><tr><td>
- <table><tr><tt>
- <thead><body><tr>
- <td> and </td>
- <row> and </row>
- <th> and </th>
- <tr> and </tr>
- Cell Spacing
- Cell Padding
- Width
- Align
- alignment
- color
- size
- spanning
- <th>
- <td>
- <tr>
- <tt>
- Table row
- Table Records
- Table heading
- Row Heading
- <head></head>
- <ttop></ttop>
- <th></th>
- <td></td>
- Used to separate cell walls from their contents
- Used to set space between cells
- Both a and b above
- Used to provide width to a cell
- Table header
- Table column
- Table row
- Table
Programs
html program to display a table with 5 rows and 4 columns. Provide appropriate heading to the form
HTML Page to display the following table
HTML Code design Time Table using rowspan and colspan
HTML Code design complex Time Table using rowspan and colspan
HTML Code to Design Basic Table
html code to design the complex table with rowspan and colspan
html table for Indian Tourist Spots