WebDevelopersNotes logo

home-icon Home / HTML / Tables tutorial in HTML – HTML Tables part 2

Tables tutorial in HTML – HTML Tables part 2

Tables tutorial in HTML - HTML Tables part 2

Now that you have understood the basic tags that comprise a HTML table let us look at some of their important attributes.

Attributes of <TABLE>

  • ALIGN: Takes LEFT, RIGHT or CENTER as value and aligns the table with respect to surrounding information. If the table is aligned to the right, any text or information will be aligned to the left of the table.
  • BACKGROUND: The value of this attribute has to be an image URL. This image is displayed as the background of the table. If the table is larger, the image is tiled.
  • BGCOLOR: Specifies the background color, hexadecimal color codes or color names accepted.
  • BORDER: We have already met this attribute in the previous section. It makes a border around the table. The thickness of this border depends on the number in pixels supplied as its value.
  • BORDERCOLOR: Table borders can be colored using this attribute. It takes hexadecimal color code or color name as value.
  • BORDERCOLORDARK and BORDERCOLORLIGHT: Works only with Internet Explorer. The default rendering of table borders is in 3D. If you don’t want this, you can specify the same color in BORDERCOLORDARK and BORDERCOLORLIGHT attributes. For such cases, BORDERCOLOR attribute should also be used with that color value so that the table display looks similar in Netscape and Internet Explorer.
  • CELLPADDING: Its value, supplied as number of pixels, denotes the amount of space between the edge of the table and its contents.
  • CELLSPACING: This attribute sets the width in pixels between the individual table cells.
  • FRAME: Its value determines the display of a frame around the table. The default value is BORDER or BOX which indicates that the table should have a frame (This works only when the BORDER attribute has a positive value). A value of ABOVE makes a frame only at the top of the table. BELOW makes only at the bottom. HSIDES and VSIDES make horizontal and vertical edges, respectively. RHS specifies only the right edge to be displayed and LHS only the left edges.
  • HEIGHT: Specifies the table height. The value has to be in pixels. (Percentage values are supported by Internet Explorer only).
  • WIDTH: determines the table width. Its value can be in pixels and results in a fixed table size or in percentages where the table width changes depending on the size of browser window.

Attributes of <TD> Tag

  • ALIGN: Its value can be CENTER, LEFT, RIGHT or JUSTIFY, which determine how cell contents are aligned.
  • VALIGN: Aligns the contents to the TOP, MIDDLE or BOTTOM of the cell.
  • BGCOLOR: Specifies background color, hexadecimal color code or color name.
  • BORDERCOLOR, BORDERCOLORDARK and BORDERCOLORLIGHT: Determines bordercolors; the last two are specific to Internet Explorer.
  • COLSPAN and ROWSPAN: Value has to be a number. The attributes are explained along with examples in the following sections… hold on.
  • HEIGHT and WIDTH: specify dimensions in pixels.

Attributes of <TR> Tag

  • ALIGN: Its value can be CENTER, LEFT, RIGHT or JUSTIFY, which aligns the content.
  • BGCOLOR: Similar to TD, above.
  • BORDERCOLOR: Similar to TD, above.

Okay, enough theory, here are a few examples.

We will make a single row table with 2 cells. We shall put a background color to add spice to an otherwise drab table.

<TD>Cell 1</TD>
<TD>Cell 2</TD>
Cell 1 Cell 2

The BGCOLOR attribute in <TABLE> defines a background green color.

What if we wanted to put a different background color in these cells? For this, we use the BGCOLOR attribute of the <TD> tag.

<TD BGCOLOR="#FF0000">Cell 1</TD>
<TD BGCOLOR="#0000FF">Cell 2</TD>
Cell 1 Cell 2

The first cell has a red background while the second has blue. If you use a background color for the table as a whole (specified by its BGCOLOR attribute) its value will be overridden by the BGCOLOR of <TD>.

Table cell contents need not be text. They can be images and other multimedia files. Let us work on the width and border of the table and try our hands at aligning cell contents.



<TD ALIGN="LEFT"><IMG SRC="apple1.gif" WIDTH="32" 
HEIGHT="32" ALT="Full Apple"></TD>

<TD ALIGN="CENTER"><IMG SRC="apple2.gif" WIDTH="32" 
HEIGHT="32" ALT="Bite taken"></TD>

<TD ALIGN="RIGHT"><IMG SRC="apple3.gif" WIDTH="32" 
HEIGHT="32" ALT="Nothing left"></TD>


Full Apple Bite taken Nothing left

The default value for CELLSPACING is 2, if we make this as 0, our table borders look neater. Don’t you think? (See below)


--- The rest of the code same as above --

Full Apple Bite taken Nothing left

BORDERCOLOR, BORDERCOLORDARK, and BORDERCOLORLIGHT are supported well only by Internet Explorer. We should not use them, if we want our pages to look similar in all browsers.

Setting the BORDER value to 0, we can create an invisible table. The table below has been centrally aligned by placing it inside a <DIV> tag (<DIV align=”center”>)



<TD ALIGN="LEFT"><IMG SRC="apple1.gif" WIDTH="32" 
HEIGHT="32" ALT="Full Apple"><BR>I'm hungry</TD>

<TD ALIGN="CENTER"><IMG SRC="apple2.gif" WIDTH="32" 
HEIGHT="32" ALT="Bite taken"><BR>Yum!</TD>

<TD ALIGN="RIGHT"><IMG SRC="apple3.gif" WIDTH="32" 
HEIGHT="32" ALT="Nothing left"><BR>Burp!</TD>


Full Apple
I’m hungry
Bite taken
Nothing left

Sponsored Links

Your comments
Star icon IMPORTANT Have a question / problem? Click here to ask an expert.

Sponsored Links


How do I view a deleted web page?
Is there a way to view a deleted web page - one that is no longer available? Yes there is and the solution is quite simple. [more...]


Wingdings included since Windows 3.1 has been the center of a strange controversy. The dingbat font contains many popular and common shapes that can quickly be incorporated in documents. In the original font, typing the three letters 'NYC' in sequence, would display skull-cross bones, star of David and thumbs up sign. Some people interpreted as an antisemitic message and raised a big hue and cry over it. In later versions, the symbols were changed to eye, heart and skyline, which is like a hat tip to the famous "I ♥ NY" logo designed by Milton Glaser. [more...]

We use cookies to give you the best possible website experience. By using WebDevelopersNotes.com, you agree to our Privacy Policy