Basic Table Tags

·

Basic Table Tags

The three most important tags for tables is the opening table tag, <table> and the table row and table data tags - <tr> and <td> respectively.
The <tr> tag represents a row for the table
The <td> tag represents a cell inside the row.
Now, with that in mind, let's create a simple table:
<table>
<tr>   <td>A</td> <td>B</td> <td>C</td>   </tr>
<tr>   <td>X</td> <td>Y</td> <td>Z</td>   </tr>
</table>
And this is what the table would look like published:
A B C
X Y Z
Notice that by looking at the code, you can tell how many rows and columns are included just by looking at the code.  The two opening <tr> tags indicate two rows and the three opening <td> tags on each line represents three data cells (or three columns).

Adding Table Borders

Adding a border simply involves inserting the border attribute to the opening table tag. So in the above table the code would be adjusted accordingly:
<table border="2">
<tr><td>A</td>  <td>B</td>  <td>C</td> </tr>
<tr><td>X</td>  <td>Y</td>  <td>Z</td> </tr>
</table>
Notice the "2" represents the thickness of the border. If you had set it to "0" then there would have been no border at all. If you wanted it very thick then you could set it to 8, for example.  So now your table will look like this:
A B C
X Y Z

Changing a Table's Border Color

You can change the color of a table border by simply adding the bordercolor attribute.
<table border="2" bordercolor="red">
<tr><td>A</td>  <td>B</td>  <td>C</td> </tr>
<tr><td>X</td>  <td>Y</td>  <td>Z</td> </tr>
</table>
And here's what it would look like...
A B C
X Y Z

Adjusting Table Cell Spacing and Cell Padding

You can increase the space within the table cells and the space between the cells by using the cellpadding and cellspacing   attributes.
The cellspacing attribute adjusts the space between the cells and cellpadding adjusts the space within (around) the cell.
<table border="2" cellspacing="10" cellpadding="3">
<tr><td>A</td>  <td>B</td>  <td>C</td> </tr>
<tr><td>X</td>  <td>Y</td>  <td>Z</td> </tr>
</table>
This is what the table would look like now...
A B C
X Y Z
See how setting the cellspacing attribute to "10" drastically increased the spacing between the cells, and the cellpadding attribute set to "3" added a little of space within each individual cell.

Specifying a Table Width

You can specify the width of a table by using either a percentage or a pixel width.
<table width="100%" border="2">
<tr><td>A</td>  <td>B</td>  <td>C</td> </tr>
<tr><td>X</td>  <td>Y</td>  <td>Z</td> </tr>
</table>
Since the width is set to 100% that means the table will take up 100% of the screen and the columns in the table will be adjusted evenly.  Here's what it would look like.
 
A B C
X Y Z
As we mentioned, you can also set the table width using pixels instead of percentages.  So instead of setting it to 100%, you could set it to 300 pixels:
<table width="300" border="2">
<tr><td>A</td>  <td>B</td>  <td>C</td> </tr>
<tr><td>X</td>  <td>Y</td>  <td>Z</td> </tr>
</table>
The table would look like this:
A B C
X Y Z

Setting Column Widths

Sometimes you may not always want your columns to be the same size.  If this is the case, you need to set values on your table data <td> cells.  Again, you can set them by using percentages or pixel widths.
<table width="300" border="2">
<tr> <td width="70%"> A</td> <td>B</td> <td>C</td> </tr>
<tr> <td width="70%"> X</td> <td>Y</td> <td>Z</td> </tr>
</table>
This is what this table would look like.

A B C
X Y Z
See how the column width for the first column in both rows is set to 70%.  Notice there is no value set for the other 2 columns.  If you do not set a value for the remaining columns, their width will automatically be adjusted to take up the remaining space and they'll share it equally.
Since the table width is set to 300 pixels, and the first column is instructed to take up 70% of those 300 pixels (roughly 210 pixels), the other 2 columns divide the remaining 30% of the table (roughly 45 pixels a piece).
You could also have expressed the column widths of this table in pixels instead of percentages.  The code would have looked like this:
<table width="300" border="2">
<tr>< td width="210" >A</td> < td width="45" >B</td> < td width="45" >C</td> </tr>
<tr>< td width="210" >A</td> < td width="45" >B</td> < td width="45" >C</td> </tr>
</table>
 
A B C
A B C
  See how the width of the columns in each row add up to 300 (210 + 45 + 45) -- which is the width of the table.

What's the Difference Between Using Percentages and Pixel Widths

Many people prefer to express their table width and column widths in percentages because that will ensure that the table takes up the same amount of screen no matter how big or small the screen resolution is.
If someone is using a 21 inch monitor to view your site and you have a table width set to 300 pixels, the table will show up very small on their screen.  However if you set the table width to 70%, it will take up 70% of the screen no matter what size the person is using.
So it's really up to you to decide what's the best layout for your tables.

Specifying a Table's Height

You can also set the table height by adding the height tag to the table code.
<table height="250" width="300" border="2">
<tr><td width="210">A</td> <td width="45">B</td> <td width="45">C</td> </tr>
<tr><td width="210">A</td> <td width="45">B</td> <td width="45">C</td></tr>
</table>
Which will produce the following table:

A B C
A B C

Horizontally Aligning the Content Inside Tables

The content inside a cell is left aligned by default, but you can also center or right align the text as well by using the align attributes.
<table width="300" border="2">
<tr><td width="210" align="center" >A</td> <td width="45">B</td> <td width="45">C</td> </tr>
<tr><td width="210" align="center" >A</td> <td width="45">B</td> <td width="45">C</td></tr>
</table>
 
A B C
A B C
See how the first column is aligned to the center?  You can also right align the columns by using the align="right" inside the <td> cells.

Vertically Aligning the Content Inside the Table Cells

So far we've kept the table cell alignment at the default, which is the middle.  Notice in the above table that the A, B, and C are all three aligned in the middle of their cells.  Well you can change their alignment to either top, bottom, or middle by using the valign (which stands for vertical align) tag:
<table height="250" width="300" border="2">
<tr><td valign="top" width="210">A</td> <td width="45">B</td> <td width="45">C</td> </tr>
<tr><td valign="top" width="210">A</td> <td width="45">B</td> <td width="45">C</td></tr>
</table>
 
A B C
A B C
I've set the table height to "250" so the alignment would be more noticeable. Notice that the A in both rows are aligned to the top.  You can also align to the "bottom" or the "middle".

Creating a Left Navigation Layout With Tables

As we mentioned earlier, most left and right navigations are created using tables.  All you do is create a table with one row, two columns and no border.  Then align both of your columns to the top (using the valign tag) so your text will start in the top of the columns, not the middle.  Depending on if you're going to have a right or left navigation, you'll make one column significantly smaller than the other.
Here's a simple left navigation layout:
<table width="100%" border="0">
<tr><td valign="top" width=" 25% ">Left Nav Links Here</td> <td valign="top" width=" 75% ">Body Here</td> </tr>
</table>
And here's what it would look like:
Left Nav Links Here Body Here
  Notice I set the border to "0" but it's still showing in the example.  I just did that to show how the layout would look. If you set your border to "0" you won't see any lines around your table.
So there ya have it!  That's a general overview of tables.  There's so much more you can do with them, but if you can understand the basic layout, you'll be able to do so much with the design of your web site.



html tags, html tutorial,html color codes,HTML codes,HTML valid,HTML color codes,HTML tutorial,HTML examples,html codes,HTML code?,HTML format,HTML text code?,HTML text codes,html web fonts,HTML Fonts,HTML Font Code,HTML font codes?, HTML Code Tutorial,html tags,,html tags chart,HTML Tags and Attributes,HTML syntax,,HTML Background,HTML code for a background,html reference,reference to HTML,HTML Reference examples,html href,HTML href Attribute,html table, HTML Table Basics.,html table color,html table border color,html table tags,html table border style,HTML Reference Guide, complete reference to HTML
 

Attributes HTML Basic Structure HTML Page Basic Table Tags Basic Text - Font Tags Binary Color Names HTML Color Values HTML Colors HTML Control Characters Conversion Table - Decimal Creating an HTML Page Elements HTML Entities HTML FONT COLOR in HTML FONT FACES in HTML FONT HEADERS in HTML FONT HIDING TEXT/TAGS in HTML FONT LOGICAL STYLES in HTML FONT PHYSICAL STYLES in HTML FONT SIZES in HTML Forms HTML Frames HTML Getting Started HTML head HTML Headings HTML Hexadecimal Horizontal Rule Examples HTML - Bold HTML - Code HTML - Div Element(s) HTML - Font and Basefont HTML - Italic HTML - Layout HTML - Strikethrough HTML -Getting Started HTML / XHTML Standard Event Attributes HTML 4.0 HTML Background HTML Basic HTML Basic - 4 Examples HTML codes HTML Codes - Characters and symbols HTML coding html color codes HTML Elements HTML Fonts HTML Tutorial List Item HTML Codes Form Input HTML Document Javascript Codes Color Code Organizing HTML HTML format HTML Introduction HTML Line Breaks HTML Marquees HTML Ordered HTML Preformatting HTML Reference HTML Style HTML Summary HTML syntax HTML Table Tags Examples II HTML Tag HTML Tags Chart HTML Tags You Really Should Know html tutorial HTML Tutorials HTML Unordered HTML URL Encode HTML URLs HTML valid HTML Webserver Image BORDERS in HTML Image FIXED BACKGROUND in HTML Image HEIGHT WIDTH in HTML Image HSPACE in HTML Image LINKED in HTML Image Map in HTML Images HTML Links HTML Lists HTML Marquee Basic Marquee Code Marquee Codes marquee right now Marquee Status Bar Marquee Tag Examples Marquee tag in html Marquee Tag of HTML marquee tag scrolling text Marquee Title Meta HTML Octal Paragraphs HTML Quick List HTML Scripts HTML Sound Tag Special Characters Struts HTML Tags Styles HTML Tables HTML Text Formatting HTML

What is HTML

free counters