Unit II Part 1-1
Unit II Part 1-1
HTML TAGS
The <html> tag represents the root of an HTML document. The <html> tag is the
container for all other HTML elements.
HTML tags are like keywords which define that how web browser will format and
display the content. With the help of tags, a web browser can distinguish between
an HTML content and a simple content. HTML tags contain three main parts:
opening tag, content and closing tag. But some HTML tags are unclosed tags.
When a web browser reads an HTML document, browser reads it from top to
bottom and left to right. HTML tags are used to create HTML documents.
You can use as many tags you want as per your code requirement.
All HTML tags must enclosed within < > these brackets.
Every tag in HTML perform different tasks.
If you have used an open tag <tag>, then you must use a close tag
</tag> (except some tags)
Syntax
Tag Description
<menuitem> It defines a command that the user can invoke from a popup
menu.
<html>
<head>
<title>Working with the Font Tag</title>
</head>
<body>
<font>
Here is text within the font tag pair.
</font>
</body>
</html>
<html>
<head>
<title>Working with the Font Tag</title>
</head>
<body>
<font size="value">
Here is text within the font tag pair.
The size attribute has been
added, but the value has not
yet been specified.</font>
</body>
</html>
<html>
<head>
<title>Working with the Font Tag</title>
</head>
<body>
<font size="4">
Here the value for the size attribute has
been set to "4", <font size="+3>one higher
than the default. I could also specify a
value of "+1"</font> to achieve the same result.
</font>
</body>
</html>
<html>
<head>
<title>Working with the Font Tag </title>
</head>
<body>
<basefont size="4">
<font size="-2">Notice that here I use the
basefont tag pair to set the base font size
to "4". In the font tag, I use the size
attribute to set the font size to "-2". I
could achieve the same results with a font
size of "2".
</font>
</basefont>
</body>
</html>
<html>
<head>
<title>Working with the Font Tag</title>
</head>
<body>
<font color="#3300ff">
Here is text within the font tag pair.
The color attribute has been
added, and a hex value specified to
make the text blue with a touch of red.
</font>
</body>
</html>
6. Nest Colors
There might be times when you want to have a few words of one color appear
within a paragraph of text in another color. To do this, simply nest one <font> tag
within another. Type <font color="#ff0000">...<font
color="#00ff00">...</font>...</font>.
<html>
<head>
<title>Working with the Font Tag</title>
</head>
<body>
<font color="#3300ff">
Here I am embedding a couple words of
<font color="red">red text</font>
within a line of blue font. Notice
that to do this I simply nest one
font tag pair within
the other.</font>
</body>
</html>
7. Add the face Attribute
Another important attribute of the <font> tag is the face attribute. Add it just as
you add any other attribute. Type <font face="value"> where value is the
desired typeface.
<html>
<head>
<title>Working with the Font Tag</title>
</head>
<body>
<font size="4" face="value">
Here I have left the size
attribute in and added
the face attribute to the font tag.</font>
</body>
</html>
8. Specify a Font
You can specify any font you desire in the face attribute. For instance, to specify
the typeface Comic Sans MS, type <font face="comic sans
ms">...</font>.
<html>
<head>
<title>Working with the Font Tag</title></head>
<body>
<font size="4" face="comic sans ms">
Here I have chosen Comic Sans MS for
the value in the
face attribute.</font>
</body>
</html>
<html>
<head>
<title>Working with the Font Tag</title></head>
<body>
<font size="4" face="comic sans ms,
arial, helvetica">
Here I have chosen Comic Sans MS for the
value in the face attribute. I also list
two alternatives: Arial and Helvetica.
Because Comic Sans MS is loaded on my
system, the alternative fonts are not
called on by the browser.</font>
</body>
</html>
Example
Unordered List
Item
Item
Item
Item
<!DOCTYPE html>
<html>
<body>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
Ordered List
An ordered HTML list:
1. First item
2. Second item
3. Third item
4. Fourth item
<!DOCTYPE html>
<html>
<body>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Definition lists are complex than the other two types of lists because they
have two elements for each item i.e., terms and definition.
E.g
<dl>
<dt>Coffee</dt>
<dd>Black hot drink</dd>
<dt>Milk</dt>
<dd>White cold drink</dd>
</dl>
Nested List
We can nest lists of the same type or different type inside another list e.g.,
Suppose we have a bulleted list and need a numbered ist beneath one of
the items.
<html>
<body>
<ul>
<li>Fruit
<ul>
<li>Bananas</li>
<li>Apples</li>
<li>Pears</li>
</ul>
</li>
<li>Vegetables</li>
<li>Meat</li>
</ul>
</body>
</html>
Tables
<table>
…………………………
</table>
The elements used in the table element are caption, colgroup, col, tbody,
thead,tfoot, tr,td,th
The <th> tag defines a header cell in an HTML table.
<!DOCTYPE html>
<html>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
<head>
</head>
<body>
<tr>
<td colspan=”2”>
</td>
</tr>
<tr>
<td> Name</td>
</tr>
<tr>
<td>Father Name</td>
<tr>
<td>Personal Address</td>
</tr>
<tr>
<td>Gender</td>
<td>
<label for="male">Male</label><br>
<label for="female">Female</label><br>
</tr>
<tr>
<td>Course</td>
<td>
<select name=”Course”>
<option value=”MCA”>MCA</option>
</select>
</td>
</tr>
<tr>
<td>Email</td>
</tr>
<tr>
<td>Mobile No.</td>
</tr>
<tr>
</tr>
</table>
</form>
</body>
</html>
Table Elements
1. Caption Element
The Caption element is used to create the caption(Heading) of the
table and used in conjunction with the <table> element.
A table should have only one caption element and t must be placed
after the starting tag of the <table> element.
e.g.
<table>
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
</table>
Output:
2. Colgroup Element
The colgroup element is used to specify the properties , such
as font color and background color, border for a group of
columns in a table.
This element is useful in applying a style to multiple columns
without defining the style again and again for each cell.
The colgroup element must be placed after the caption
element and before TBODY, THEAD, TFOOT,TR elements.
e.g
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
</style>
</head>
<body>
<table>
<colgroup>
<col span="2" style="background-color:red">
<col style="background-color:yellow">
</colgroup>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>$53</td>
</tr>
<tr>
<td>5869207</td>
<td>$49</td>
</tr>
</table>
</body>
</html>
Output
3. Col Element
Col Element is used to define the properties of each column of a
table separately.
The Col element can be defined in the Colgroup element, which itself
is defined in the <table > element.
Each Col element in the Colgroup element represents a column of
the table.
4. TBody Element
The Tbody element is used to group the rows of a table and is used in
conjunction with the Thead and Tfoot elements.
These three elements determine the body,head and footer of the
table.
They allow us to scroll freely throughout the body section and
provide a fixed height to the table.
e.g.
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
</table>
</body>
</html>
5. Thead Element
The Thead element is used to define the header for the tale and is
used in conjunction with Tbody and Tfoot elements.
We must define Thead of the <table> element after caption, and
colgroup elements and before TBody, TFoot and TR elements.
6. Tfoot Element
The Tfoot element is used to define the footer for the table and s
used in conjunction with Tbody and the Thead.
We must define Tfoot element in the <table> element after Caption,
Colgroup and Thead element and before the Tbody and Tr Element.