Table Tags

Posted on

The basic grammar of tables

< Table >… < / Table > – define table
< tr > – define table rows
< th > – define header
<td>- define table elements (table specific data)

Table with border:

Copy code

The code is as follows:

<table border>
<tr><th>Food</th><th>Drink</th><th>Sweet</th>
<tr><td>A</td><td>B</td><td>C</td>
</table>
Food Drink Sweet
A B C

Table without border:

Copy code

The code is as follows:

<table>
<tr><th>Food</th><th>Drink</th><th>Sweet</th>
<tr><td>A</td><td>B</td><td>C</td>
</table>

Food Drink Sweet
A B C

Table span across multiple rows and columns

Table elements that span multiple columns < th colSpan = # >

Copy code

The code is as follows:

<table border>
<tr><th colspan=3> Morning Menu</th>
<tr><th>Food</th> <th>Drink</th> <th>Sweet</th>
<tr><td>A</td><td>B</td><td>C</td>
</table>

Morning Menu
Food Drink Sweet
A B C

Table elements that span multiple rows < th rowspan = # >

Copy code

The code is as follows:

<table border>
<tr><th rowspan=3> Morning Menu</th>
<th>Food</th> <td>A</td></tr>
<tr><th>Drink</th> <td>B</td></tr>
<tr><th>Sweet</th> <td>C</td></tr>
</table>
Morning Menu Food A
Drink B
Sweet C

Table size settings

<table border=#>

Border size setting:

Copy code

The code is as follows:

<table border=10>
<tr><th>Food</th><th>Drink</th><th>Sweet</th>
<tr><td>A</td><td>B</td><td>C</td>
</table>
Food Drink Sweet
A B C

<table border width=# height=#>

Table size setting:

Copy code

The code is as follows:

<table border width=170 height=100>
<tr><th>Food</th><th>Drink</th><th>Sweet</th>
<tr><td>A</td><td>B</td><td>C</td>
</table>
Food Drink Sweet
A B C

<table border cellspacing=#>

Table element gap setting:

Copy code

The code is as follows:

<table border cellspacing=10>
<tr><th>Food</th><th>Drink</th><th>Sweet</th>
<tr><td>A</td><td>B</td><td>C</td>
</table>
Food Drink Sweet
A B C

<table border cellpadding=#>

Table element internal blank setting:

Copy code

The code is as follows:

<table border cellpadding=10>
<tr><th>Food</th><th>Drink</th><th>Sweet</th>
<tr><td>A</td><td>B</td><td>C</td>
</table>
Food Drink Sweet
A B C

Alignment / layout of text in tables

<tr align=#>

<th align=#> #=left, center, right

<td align=#>

Copy code

The code is as follows:

<table border width=160>
<tr>
<th>Food</th><th>Drink</th><th>Sweet</th>
<tr>
<td align=left>A</td>
<td align=center>B</td>
<td align=right>C</td>
</table>
Food Drink Sweet
A B C

<tr valign=#>

<th valign=#> #=top, middle, bottom, baseline

<td valign=#>

Copy code

The code is as follows:

<table border height=100>
<tr>
<th>Food</th><th>Drink</th>
<th>Sweet</th><th>Other</th>
<tr>
<td valign=top>A</td>
<td valign=middle>B</td>
<td valign=bottom>C</td>
<td valign=baseline>D</td>
</table>
Food Drink Sweet Other
A B C D

Alignment / layout of tables in pages

<table align=left>

Copy code

The code is as follows:

<table align=”left” border>
<tr><th>Food</th><th>Drink</th><th>Sweet</th>
<tr><td>A</td><td>B</td><td>C</td>
</table>

My favorites…<br> cookies, chocolates, and more.

Food Drink Sweet
A B C

My favorites…
cookies, chocolates, and more.

<table align=right>

Food Drink Sweet
A B C

My favorites…
cookies, chocolates, and more.

<table vspace=# hspace=#> #=space value

Copy code

The code is as follows:

<table align=”left” border vspace=20 hspace=30>
<tr><th>Food</th><th>Drink</th><th>Sweet</th>
<tr><td>A</td><td>B</td><td>C</td>
</table>

 My favorites…<br> cookies, chocolates, and more.

Food Drink Sweet
A B C

My favorites…
cookies, chocolates, and more.

The title of the form

<caption align=#> … </caption> #=left, center, right

Copy code

The code is as follows:

<table border>
<caption align=center>Lunch</caption>
<tr><th>Food</th><th>Drink</th><th>Sweet</th>
<tr><td>A</td><td>B</td><td>C</td>
</table>

Lunch

Food Drink Sweet
A B C

<caption valign=#> … </caption> #=top, bottom

valign=top is default.

Copy code

The code is as follows:

<table border>
<caption valign=bottom>Lunch</caption>
<tr><th>Food</th><th>Drink</th><th>Sweet</th>
<tr><td>A</td><td>B</td><td>C</td>
</table>

Food Drink Sweet
A B C

Lunch

Leave a Reply

Your email address will not be published.