Tables HTML
Tables HTML
155
4.7Tobles
TheHTML table model allows you to
form fields, other tables, etc. arrange data - text, preformatted text,
- into rows and
columns of cells. inages, li1KS, jorns,
Each table may have an
associated caption (given through the
CAPTION element) that provides a short
purpose. A longer description may alsodescription of the table's Tables are useful for the
be provided (via the general display of tabular
summary attribute) for the benefit of people &data.
Braille-based user agents. using speech or
Table Caption
The PACEians
Monica Carol1ne Gauri S.
Table Rows
Kush Ragin1 Shalu (3 rows )
Warun Sunila Rocky
Table Data
in third row
<HTML>
<BODY>
4
<TABLE> <TABLE> starts and ends the entire thing,
<CAPTION>The PACEians«/CAPTION>
<TR>
<CAPTION> and </CAPTION> places a caption over
<TD> Monica </TD> centered.
your table. The caption will be bold and
<TD> Caroline </TD>
<TD> Gauri S. </TD>
3 <TD>s <TR> is used when you want a new Table Row to begin
</TR> Notice that you need to end every table row with
an </TR
for 3 cells
in the row <TR> 4
<TD> Kush </TD>
<TD> Ragini </TD> <TD> denotes Table Data. You put this in front of every
cell.
<TD> Shalu </TD> piece of information you want in a
You need to end every one that you open with an </TD>
</TR>
<TR>
<TD> Varun </TD>
<TD> Sunila </TD>
</TABLE> ends the whole table narkup.
<TD> Rocky </TD>
</TR>
</TABLE>
</BODY>
</HTML> Note
Though the program above
Can you make out something from above code ? It looks has each cell (or TD)
rough, but look again. There are really only four commands command on a new line, the
(TABLE, CAPTION, TR and TD) being used again and again. cells keep going to the right
until you tell the computer
What Is Happening ? that a new roW of cells will
What table commands do is create a series of cells. Each start by using the <TR> or
cell's data is denoted by the <TD> command, i.e., Table's Table Row command.
Data.
Use the <TD> Command to make three cells across, use <TR> to jump to the next row, and so
on until you have nine cells in three rows of three. Nothing to it.
Remember that whatever follows the <TD> command willappear in the cell. And the cells, by
column, willbe of equal size using the largest cellas the model for the others. Biggest wins, in
other words... in life, as in HTML. :)
HTML Table Tags
After getting introduced to tables, let us learn about table tags formally. We shall be
discussing these table tags henceforth:
<TABLE>
<TBODY>
’ <THEAD>
<TFOOT>
<TR>
<TD>
<TH>
HTML II : IMAGES, LINKS AND TABLES 15/
Inorder to demonstrate each
of these comnands. we'll
work with this very simple table
<TABLE BORDER="1"> format:
<TR>
<TD>Cell Datas/TD>
<TD>Cell Datas/TD>
</TR>
<TR>
<TD>Cell Data</TD>
<TD>Cel1l Data</TD>
</TR>
</TABLE>
A table's border is specified through BORDER attribute. The BORDER attribute tells the table
how largethe border should be. This is all relative in terms of pixels. Three is larger than two and
two is larger than one, etc. You can try different numbers. I happen to like the look of BORDER-3.
BORDER-0 getsrid of the borders altogether. Notice the following example code.
cHTML
<BODY>
<IABIF BORDE R- "1" FRAME ="hsides",
<TR>
<TD>Cell Data</TD>
<TD>Cell Data</ TD>
</TR> bottom edges
HIML - II: IMAGES, LINKS AND TABLES 159
<TR>
<TD>Ce1l Data</TD>
<TD>Cell Data</TD>
</TR>
</TABLE>
<p>
<TABLE BORDER="1" FRAME="lhs">
<TR>
<TD>Cell Data</TD>
<TD>Cell Data</TD>
</TR>
<TR>
<TD>Cell Data</TD>
<TD>Cell Datas/TD> The output produced is as shown below
</TR>
</TABLE> Mozilla Firefox-OX
Ele Edk yow Hgtory Book
<p>
<TABLE BORDER="1" FRAME="above">
<TR> PMost isited
</BODY> Dons
</HTML>
The RULES attribute like FRAME, also works with the BORDER attribute, except RULES
deals with the inside border edges.
</HTML>
This example is
trying to align a
table
alignment.
"left">
<TABLE BORDER="3" AL IGN =
<TR>
<TD>Cell Data</TD>
<TD>Cell Data</TD>
</TR>
<TR>
<TD>Cell Data</TD>
<TD>Cell Data</TD>
</TR>
</TABLE>
This example is trying to align atable according to specified alignmens
This example is trying to align a table according to specified alignment.
This example is trying to align a table according to specified alignment.
<TABLE BORDER="3" ALIGN = center?>
<TR>
<TD>Cell Data/TD>
<TD>Cell Data</TD>
</TR>
<TR>
<TD>Cell Data</TD>
<TD>Cell Data</TD>
</TR>
</TABLE>
This example is trying to align a table
This example is trying to align a table according to specified alignment.
according to specified
table according to specified alignment.
This example is trying to align a
<TABLE BORDER="3" ALIGN = right"> alignment.
<TR>
<TD>Cell Data</TD>
<TD>Cell Data</TD>
</TR>
<TR>
<TD>Cell Data/TD>
<TD>Cell Data</TD>
</TR>
</TABLE>
This example is trying to
This example is trying to align a table
This example is trying to align a table according to specified alignment.
align atable according to specified alignment.
</BODY> according to specified alignment.
</HTML >
HTML - II: IMAGES, LINKS AND TABLES 163
file:/|D:JFIT-XJChap_6/Ex6-17.!
This example is trying to ahgn atable accor ding to spectfied algrment This exarple is
trying to align a table according to specifhed alignment. Thus exarnple is tryng to aign a
Result of ALIGN = "left table according to specifed alignment This example is trying to align atable accordng
attribute. See table is left Cell Data lCell Data to specitied alignment Ths example is trying to ahgm a table
aligned wrt text in browser. according to specfied akgnment. Thás exarnple is trying to align a
Cell Data Cel Data able according to specified aligment.
Result of ALIGN ="center Cel Data Cell Data
attribute. See table is center Cell Data CellData
aligned wrt text in browser
align a table according to specified ahgnment. This exanple is
tryng to align atable according to specfied alignment This exarnple is trying to align a
table according to spectfied aignment. This example is trying to ahgn a table according
to specied aligment. Thic evamnle ic fring to akan atable Cell DataCell Data
according to speciied| Result of ALIGN = "right" a Cell Data Cel Data
table according to speattribute. See table is right
aligned wrt text in browser
Done
OMozilaFiretox - X
Change the
browser window
size and See
Mot Visited the effect on
table with height
Cell Cell Result of HEIGHT=100 and width in
Data Data WIDTH =70 attributes. percentage size
Cell Cell of browser
Data Data window.
Cell Cell
Data Data Result of HEIGHT=40%
Cell Cell WIDTH =60% attributes.
Data Data
Done
Many attributes of TABLE tag are not supported in HTML5.The formatting these attributes
used to do is now done via CSS.
Attribute Description
align Specifies the alignment of a table according to surrounding text
Not supported in HTML5.
bgcolor Specifies the background color for a table
Not supported in HTML5.
border Specifies whether the table cells should have borders or not
Not supported in HTML5.
cellpadding Specifies the space between the cellwall and the cell content
Not supported in HTML5.
cellspacing Specifies the space between cells
Not supported in HTML5.
frame Specifies which parts of the outside borders that should be visible
Nof supported in HTML5.
rules Specifies which parts of the inside borders that should be visible
Not supported in HTML5.
width Specifies the width of a table
Not supported in HTML5.
166 COMPUTER APPUCATIONS X
Done
168 COMPUTER APPLICATIONSX
In this table (Table 1), cell 2 of first row, In this table (Table 2), cell 2 of first row.
has a span of two rOws. has a span of twO columns.
Such type of cells can be created with the help of ROWSPAN and COLSPAN attributes of
<TD> tag.
For Table 1shown above, we shall write the code as :
<TABLE BORDER>
<TR>
<TD>Item 1</TD> <TD ROWSPAN = 2>Item 2</TD> <TD> Item 3 </TD>
</TR>
<TR>
<TD>Item 4</TD> <TD>Item 5</TD>
</TR>
</TABLE>
Example 4.20 To create a table with cells having different row and column spans.
<HTML>
<BODY>
<TABLE BORDER>
<TR>
<TD ALIGN=center ROWSPAN=2
COLSPAN=2>A</TD>
<TD>1</TD>
<TD>2</TD>
</TR>
HTML I|: IMAGES, LINKS AND TABLES 169
<TR>
The output produced is
<TD>3</TD> as shown below
<TD>4</TD>
</TR> Mozilla ...DX
Fde Edt Hew Higtory
<TR>
<TD ALIGN=center ROWSPAN=2 COLSPAN=2>C</TD>
<TD ALIGN=center ROWSPAN=2 COLSPAN=2>D</TD> Mot Veted
</TR>
12
<TR> B4
</TR> D
</TABLE>
Done
</BODY>
</HTML>
<TD> Tag
Vertical Alignment of Cell Contents VALIGN Attribute
Type
In cells that have span of more than one rows, data can also Container Element
be vertically aligned using VALIGN attribute. The possible Function
values that a VALIGN attribute may take are: top, middle and Defines table data
bottom. Consider the following code:
Attributes
Align, Width,
Cxample 4.21 To vertically align a cell's contents. Background, Bgcolor,
<HTML> Rowspan, Colspan,
<BODY>
Valign etc.
<TABLE BORDER> | Contains
<TR> Table Data
<TD VALIGN=bottom ROWSPAN=2 COLSPAN=2>A</TD> Used Inside
<TD>1</TD> <TABLE>...TABLE>
<TD>2</TD>
</TR>
<TR> The output produced is as shown below
<TD>3</TD> WMozilla Firefox
<TD>4</TD> Ele Edit Vew H_tory Bookmarks Io
</TR>
<TR> AMost Visited Getting Started
</TR> i2
</TABLE>
Notice the bottom alignment
A34 [<TDVALIGN = bottom > ]
</BODY>
</HTML>
Done
Attribute Description
align Aligns the content in a cell Not supported in HTML5
bgcolor Specifies the background color of a cell Not supported in HIML5.
valign Vertical aligns the content in a cell Not suported in ITML5.
width Specifies the width of a cell Not supported in HIML5.
170 COMPUTER APPLICATIONS-X
TH> Tag
4.7.4 The <TH and <TR> Tags
Type
because everything that
we are grouping these two tags together Container Element
is new to them has been covered above.
Function
TH Tag defines table header
header are
It stands for Table Header. The contents declared as Attributes
displayed in a distinctive style e.g.. boldfaced. It will accept the Align, Width,
same attributes as the <TD> command above. Following example Background, Bgcolor,
code uses <TH> to define table headers. Rowspan, Colspan,
Valign etc.
Lxample 4.22 To use table header tag. | Contains
<HTML>
Table Header
<BODY> Used Inside
<TABLE BORDER> <TABLE> <TABLE>
<TR>
<TH>Head1</TH> <TH>Head2</ TH> <TH>Head3</TH>
</TR>
<TR>
<TD>A</TD> <TD>B</TD> <TD>C</TD>
</TR>
<TR>
<TD>D</TD> <TD>E</TD> <TD>F</TD>
</TR>
</TABLE>
</BODY>
</HTML>
<TR> Tag
And the output produced by above code is as shown below Type
Container Element
Mozilla Firefox
Ele Edit Ylew Migtory Bookmarks Io
Notice the style of table Function
headers here.
Table headers are the Defines table row
contents given in
Most visited Getting Started <TH>...</TH> tags. Attributes
Headl He ad2 Head3 Align, Width,
A Background, Bgcolor,
D F Rowspan, Colspan,
Valign etc.
Done
Contains
Table Row
TR Tag
Used Inside
It stands for Table Row. It also uses similar attributes as
that of TD <TABLE> <TABLE>
(TABLE BORDER="1">
<THEAD BGCOLOR="pink">
<TR>
<TD>Cell Data</ TD>
<TD>Cell Data</TD>
</TR> <THEAD> Tag
</THEAD> Type
<TR> Container Element
<TD>Cell Data</ TD> Function
<TD>Cell Data</TD>
defines header
</TR> section of table
</TABLE>
Attributes
</BODY>
</HTML >
Align, Bgcolor.,
Valign etc.
|Contains
If a table is very big and is spanning across pages then the Table Header Rows
rows set by THEAD will be replicated on every page where Used Inside
this table is displayed. Further, you can specify desired <TABLE>... </TABLE>
settings to multiple table header rows through attributes
specified in THEAD tag. In fact, THEAD defines the table
header section that may have multiple rows in it.
The THEAD tag will handle these attributes just like other tags.
ALIGN
BGCOLOR
VALIGN
<TBODY> Tag Example 4.24 To display various table sections using THEAD,
Iype tags.
TBODY& TFOOT
Container Element
Function <HTML )
defines body <BODY>
section of table <TABLE BORDER="1">
Attributes <THEAD BGCOLOR="pink">
<TR>
Align, Width,
Background, Bgolor, <TD>Header rll</TD>
Event handlers etc <TD> Header r12</TD»
Contains </TR>
<TR>
Table data
Used Inside <TD>Header r21</TD>
<TD> Header r22</ TD>
<TABLE>...<TABLE> </TR>
</THEAD>
HTML II: IMAGES, LINKS AND TABLES 173
<TBODY bgcolor="yellow'" >
<TR>
<TD>BODY Cell datal</TD>
<TD> BODY Cell data 2</TD>
</TR>
<TR>
<TD>BODY Cell 3</TD>
<TD> BODY Cell 4</TD>
</TR>
The output produced is as shown below
<TR>
<TD>BODY Cell 5</TD> Mozilla Firefox
File Edt ylew History Bonkmarks Tonk Helo
<TD> BODY Cell 6</TD>
Fle:l/D
</TR>
</TBODY> Most Visited Getting Started Latet Hearines Same settings
applied to table
<TFOOT ALIGN=center bgcolor=cyan> Header rll Header rl2 header rows
<TR> Header r21 Header r22 using
<THEAD> tag.
<TD>Footer Data</TD> BODY Cell datalBODY Cell data 2
<TD>Footer Data</TD> BODY Cell 3 BODY Cel 4
Images can be inserted in text using <IMG> tag. Its source is specified with sre attribute, alternate Let Us
text with alt attribute, alignment with align attribute and size with height and width attributes. Revise
Internet explorer can display alt text (of an image) as tooltip.
* In browsers other than Internet explorer, titile attribute of image can be used to define tooltip text.
* Documents can be linked i.e., hyperlinks can be created using <A> tag. Linking to another document is
called external linking.
* Hyperlinks can also be created for links within the same document. Linking within the same document is
called internal linking.
* HTML able model allows one to arrange data into rows and columns of cells.
* An HTML table is presented and manipulated with the help of these tags <TABLE>, <TBOY>, <THEAD>,
<TFO0T>, <TR>, <TD>, and <TH>.
* The <TABLE> tag begins the process of building atable. It may use attributes like, BACKGROUND,
BGCOLOR CELLPADDING, HEIGHT, WIDTH, CELLSPACING, WIDTH, ALIGN, FRAME and RULES.
The <TD> tag is workhorse of the table. It denotes table data. It may use attributes like ALIGN, WIDTH,
BACKGROUND, BGCOLOR, ROWSPAN, COLSPAN, and VALIGN.
* The <TH tag is used to specify Table Header. It accepts the same attributes as that of <TD> tag.
* The <TR- tag is used to specify Table row. It also used similar attributes as that of <TD> except for
ROWSPAN and COLSPAN.
* The <THEAD> tag is used to define aset of header roWs, <TBODY» for defining table body rows and <tFO0
1S used for defining set of footer rowS.
* Table's backqround may be specified with background attribute of «Table> tag and table's
background color may be defined through bgeolor attribute of <Table> tag.
* Summary attribute of <Table> tag lets you denote summary of table's data.
174 COMPUTER
APPLICATIONS X
Assisted Practice
SECTION A: Objective TypeQuestions
1. To jump to new
page, we use 10. The default alignment of images, that are inserted
(a) <IMG> tag (b) <A> tag in Web page, is : [CBSE SP 2021-22, Term I]
(c) <JUMP> tag (d) none of the above (a) Left (6) Right
2. Which of the following is not a (c) Inline with text (d) Middle
valid value for
align attribute of <IMG> ? 11. Border, frame, cellspacing, cellpadding, align
(a) top (b) middle are the attributes of
(c) bottom (d) center (a) <BODY> (b) <IMG>
3. If the image you are loading in the web (c) <TABLE> (d) None of these
not available, then you want a text to page is 12. To create a link yousurround the text or image
appear in
the image place holder, which attribute lets with a(n) tag.
you define this text ? (a) link (b) anchor
(a) src (b) align (c) text (d) alt (c) reference (d) target
4. For linking to another web page, its URL 13. The correct HTML code for inserting an image
is
specified with is : [CBSE SP 2021-22, Term I]|
attribute of <A> tag
(a) href (b) title (a) <img href ="image.gif">
(C) name (d) none of the above (b) <img> image.gif</gif>
5. For internal linking, the section names are (c) <image src = image.gif">
provided by attribute of <A> tag ? (d) <img src = "image.gif" >
(a) href (b) title 14. Which will let text wrap down the side of the
(c) name (d) none of the above image?
6
attribute is used to specify the location (a) <img src="mylmage.gif" align="wrap'>
of an image file. [CBSE SP 2021-22, Term I| (b) <img src='mylmage.gif" align="right'>
(a) alt (b) src (c) <img src="mylmage.gif" wrap="on'>
(c) align (d) name 15. Consider the following
7. The code:
attribute of <img> tag specifies an <img src
alternate text for an image, if the image cannot ="Computers.jpg" width =" "height =" ">
be displayed due to any reason. Fill in the blanks to set the image
size to be
(a) alt (b) alternate 250 pixels wide and 400 pixels tall.
(c) tooltip (d) text
(a) 250, 400 (b) 400, 250
(c) <250><400> (d) <400X250>
[CBSE SP 2021-22, Term I|
8. The default alignment of images, that are [CBSE SP 2021-22, Term I)
inserted in the web page, is 16. The correct HTML code
to display (P+Q) is:
(a) left (b) right (a) <sUB> (P+) 2</SUB>
(c) middle (d) inline with text (b) P+Q <SUP> 2 </SUP>
9. While creating a Web document, which unit is (c) (P + Q) <SUP> 2 </SUP>
used to express an image's heightand width ? (d) <sUP> (P+Q) 2</SUP>
(a) Centimetres (b) Pixels [CBSE SP 2021-22, Term I]
17. The <
(c) Dots per inch (d) Inches > tag displays text in subscript
[CBSE SP 2021-22, Term ! form. |CBSE SP 2021-22, Term I]
(a) sub (b) sup (c) sups (d) subs
HTML II: IMAGES, LINKS AND TABLES 175
cell is
18. The tag that starts a table (c) These attributes constrain the image's
(a) <table> (b) <tc> proportions.
(c) <td> (d) <tr> (d) Specifying these dimensions helps a
browser render pages faster.
19. What tag is used to add columns to tables 2
28. Which one of the following HTML tags is
(a) <colspan> (b) <td> (c) <tr> surrounded by <a><la> container tags to create
20. Which has higher priority,cell settings or table an image link ?
settings ? (d) <pic
(a) <img> (b) <ul> (c) <br>
(a) Neither (b) Cell settings 29. What is the general syntax for inline image ?
(c) Table settings (a) <src = img> (b) <src= image>
21. Choose the correct HTML to left-align the (c) <img = file> (d) <img src = file>
content inside a table cell
(e) <image src = file>,
(a) <td valign="left" 30. To create a link to an anchor, you use
(b) <tdleft> (c) <td align="left'> the property in A tag.
(d) <td leftalign> (a) Name (b) Tag (c) Link (d) Href
22. Which of these tags are all <table>tags ? 31. Which of the following is used to specify the
(a) <thead><body><tr> (b) <table>xtrxtd> beginning of a table's row ?
(c) <table><head><tfoot> (d) <table><tr><tt> (a) TROW (b) TABLER
(c) TR (d) ROW
23. Settings for columns(<td> tag) have higher
priority than settings for rows(<tr> tag) 32. In order to add border to a table, BORDER
(a) Sometimes true, sometimes not attribute is specified in which tag ?
(a) THEAD (b) TABLE
(b) True (c) False
(c) TBORDER (d) none of these
24. Which property tells how many rows a cell
should span ? 33. Which of the following is an attribute of
<Table> tag ? [CBSE SP 2011, Term II]
(a) colspan=n (a) SRC (b) LINK
(b) Both rowspan=n and colspan=n (c) CELLPADDING (d) BOLD
(c) rowspan=n 34. What is the correct syntax in HTML for creating
25. What is required to create a reference to a alink on a webpage ? [CBSE SP 11, Term II)
remote site that is different from creating a (a) <LINK SRC = "abc.html">
local link ?
(b) <BODY LINK = "abc.html">
(a) The remote attribute (b) A link title (c) <A SRC = "abc.html">
(c) The Web address of the remote site
(d) <A HREF = "abc.html">
(d) An extra <a> tag 35. Choose the correct HTML code to create an
26. Which one of the following is the list type that email link ?
will create a bulleted list?
(a) <A HREF = "[email protected]"></A>
(a) unordered (b) option (b) <A HREF = "mailto:[email protected]"></A>
(c) decorated (d) ordered (c) <MAIL ="[email protected]"></MAIL>
27. Why is it important to specify an image width (d) <A MAILHREF = "[email protected]">x/A>
and height in an <img> tag ? [CBSE Sample Paper 2011, Term II|
(a) It ensures that a user will not be able to 36. attribute is used with <A> tag to specify
copy the image to their computer. the URL of link. [CBSE SP 2011, Term I|
38. ROWSPAN attribute with <TABLE> tag is used 40. Align and Valign are the attributes used
to merge more than one cell row wise. (T/E) with <TD> tag to set the alignment of data in a
|CBSE Sample Paper 2011, Term II| table. (T/E) (CBSE Sample Paper 2011, Term I|
39, Target attribute with <A> tag is used to open a 41. BORDER is an attribute of <A> tag. (T/F)
link in a new window. (T/F) (CBSE SP 2011, 1| |CBSE Sample Paper 2011, Term I
manyrows focusing the table body and many rows depicting the table footer. If these are to be rendered
in
different manners, table sections can be created. A
table can be dividedinto these sections :
, table header with <THEAD> tag table body with <TBODY> tag
table footer with <TFOOT> tao
k Consider the following HTML statement:
<body bgcolor = "Blue" alink = "red" vlink = "yellow">
In the above statement, what do you mean by 'alink' and 'olink' ? [CBSE Sample Paper 2019-20|
Ans. Alink is for active link while vlink is for visited link. When ahyperlink becomes active, ie., when the
mOuse cursor moves over it, its colour will become as specified in alink attribute. And when a hyperlink is
dlicked, its colour changes to the colour as specified in vlink attribute.
As per above code, active hyperlink will show in red and once visited, it will be of yellow colour.
7. Consider following code :
<html>
<head>
<tr
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<trxtdrowspan="2">AAA X</td><td>AAA Y</td><td>AAA
Z</td></tr>
<trxtd> BBB Y</td><td>BBB
Z</td></tr>
<tr><td colspan="3">CCCX</td></tr>
</table>
</body>
</html>
From the following four sample tables, identify which one willbe created by above code:
(a) (c)
Column 1 Column 2 Column 3 Column 1 Column 2 Column 3
AAA X AAA Y AAA Z AAA X AAA Y AAA Z
BBB Y BBB Z BBB Y BBB Z
CCC X BBB Y BBB Z CCC X
(b) (d)
Column 1 Column 2 Column 3 Column 1 Column 2 Column 3
AAA X AAA Y AAAZ AAA X AAA Y AAA Z
BBB Y BBB Z
CCC X BBB Y BBB Z CCC X
Alpha 1 2 3
Ans.
<HTML>
<HEAD><TITLE> A Table </TITLE>
</HEAD>
<BODY>
<TABLE border=1>