HTML final unit 1
HTML final unit 1
Tag BASICS
HTML defines three tags that are used to define the page’s overall structure and provide some
simple header information. These three tags—<html>, <head>, and <body>—make up the basic
skeleton of every web page. They also provide simple information about the page (such as its title or
its author) before loading the entire thing.
The Title
Each HTML page needs a title to indicate what the page describes. It appears in the title bar of the browser
when people view the web page. The title is stored in your browser’s bookmarks and in search engines when
they index your pages. Use the <title> tag to give a page a title.
<title> tags are placed within the <head> tag and are normally used to describe the contents of the page, as
follows:
<!DOCTYPE html><html>
<head>
<title>The Lion, The Witch, and the Wardrobe</title>
</head>
<body> ...your page...
</body>
</html>
Each page can have only one title, and that title can contain only plain text; that is, no other tags should appear
inside the title.
Figure 4.1 shows how the follow ing title looks in a browser:
<title>The Lion, the Witch, and the Wardrobe</title>
FIGURE 4.1
The title appears in the tab bar, not on the page.
The basic document starts with <HTML> and ends with </HTML>
The HEAD part of the document contains information about the document namely,
• Title of the page which appears at the top of the browser window).
• Meta tags which is used to describe the information about the content that is in the
document (used by Search engines).
• The script code written in JavaScript and Style sheets generally appears in the document
Head.
The BODY part of the document contains the actual content of the document. This is the part
that will be displayed in the browser window.
<HTML>
<HEAD>
</HEAD>
<BODY>
</BODY>
</HTML>
Comments
You can put comments into HTML pages to describe the page itself or to provide some kind of
indication of the status of the page. Some source code control programs store the page status in
comments, for example. Text in comments is ignored when the HTML file is parsed; comments never
show up onscreen—that’s why they’re comments. Comments look like the following:
<!-- This is a comment -->
Here are some examples:
<!-- Rewrite this section with less humor -->
<!-- Neil helped with this section -->
<!-- Go Tigers! -->
As you can see from Figure 4.4, users can view your comments using the View Source functionality in their
browsers, so don’t put anything in comments that you don’t want them to see.
FIGURE 4.4
HTML
comments
displayed within
the source for a
page.
Paragraphs
A paragraph in HTML is simply a block of text enclosed within the <p>
tag. The <p> tag helps divide content into manageable, readable
sections. It’s the go-to element for wrapping text in a web page that is
meant to be displayed as a distinct paragraph.
Syntax:
<p> Content</p>
<p>Slowly and deliberately, Enigern approached the mighty dragon. A rustle in the trees of the
nearby forest distracted his attention for a brief moment, a near fatal mistake for the brave
knight.</p>
Input ▼
<p>The dragon fell to the ground, releasing an anguished cry and seething in
pain. The thrust of Enigern's sword proved fatal as the dragon breathed its
last breath. Now Enigern was free to release Lady Aelfleada from her
imprisonment in the dragon's lair. </p>
Output ▼
FIGURE 4.3
An HTML para-
graph.
The closing </p> tag, while not required, is important for defining the exact contents of a paragraph for CSS.
Most web designers use it automatically, but if you don’t need it, you can leave it out of your HTML.
This tag breaks the line and starts text at a new line. It will not add an empty line like the
paragraph tag. Multiple <br> tags will display multiple line breaks in the text. Spaces
and line breaks are supported without additional elements or special characters.
Emphasized text
The <em> tag in HTML is a phrase tag and is used to emphasize the text
content. It is similar to <italic> tag. The main difference between these two
tags is the <em> tag semantically emphasizes the important word or
section of words while the <i> tag is just offset text conventionally styled in
italics to show an alternative mood or voice.
Syntax:
<em> Contents... </em>
Example 1: This example uses <em> tag to create emphasized text.
HTML
<!DOCTYPE html>
<html>
<head>
<title>
How to render as emphasized
text using HTML?
</title>
</head>
</html>
Output:
Output
Headings
Headings are used to add titles to sections of a page. HTML defines six levels of headings. Heading tags look
like the following:
<h1>Installing Your Safetee Lock</h1>
The numbers indicate heading levels (h1 through h6). The headings, when they’re displayed, aren’t numbered.
They’re displayed in larger and bolder text so that they stand out from regular text.
Think of the headings as items in an outline. If the text you’re writing is structured, use the headings to express
that structure, as shown in the following code:
Input ▼
Output ▼
FIGURE 4.2
HTML heading ele-
ments.
Unlike titles, headings can be any length, spanning many lines of text. Because headings are emphasized,
however, having many lines of emphasized text might be tiring to read.
A common practice is to use a first-level heading at the top of your page to either duplicate the title or to provide
a shorter or less context-specific form of the title.
<hr width=“70%”>
Lists
Lists are used to organize items in the browser window. There are two ways to create a list
namely, Unordered list which is a Bulleted list and it is most popular. Here, list items have no
particular order. The other list is an Ordered list or Numbered list.
Basic Syntax:
Unordered Lists
Fruit
<UL>
<LI>Banana
<LI>Grape
</UL>
We have the choice of setting the TYPE Attribute to one of five numbering styles.
<OL
type=I or i (for large or small roman numerals) type=A or a (for capital or small letters) type=1
(for numbers, which is the default)>
<UL
type=disc (the default for first level lists) type=round (the default for second level lists)
type=square (the default for third level lists) >
Fruit
<OL>
<LI> Banana
<LI>Grape
</OL>
</OL>
</OL>
</OL>
List Elements
DL: Definition List.
This kind of list is different from the others. Each item in a DL consists of one or more Definition
Terms (DT elements), followed by one or more Definition Description (DD elements).
<DL>
</DL>
HTML
DOG
FONT SIZE
The HTML <font> size attribute adjusts text size within `<font>` elements,
simplifying font size modification directly.
The size attribute can be set within the <FONT> tag as an absolute value from 1 to 7 or as a
relative value using the “+” or “-” sign. Normal text size is 3 (from -2 to +4).
Syntax:
<font size="number">
Attribute Values:
It contains a single value number that specifies the size of the text. The
font size lies between 1 to 7. The default value of font size is 3.
<!DOCTYPE html>
<html>
<head>
<title>HTML font size Attribute </title>
</head>
<body>
<font size="1">GeeksforGeeks! </font><br />
<font size="2">GeeksforGeeks! </font><br />
<font size="3">GeeksforGeeks! </font><br />
<font size="4">GeeksforGeeks! </font><br />
<font size="5">GeeksforGeeks! </font><br />
<font size="6">GeeksforGeeks! </font><br />
<font size="7">GeeksforGeeks! </font>
</body>
</html>
Output:
Attribute Values:
Example
Type How It Works Usage
Color Pick from common color names to set the text "red"
Name color.
Hex
Use a 6-digit hex code to define specific colors. "#0000ff"
Code
RGB Define colors using the RGB model with three "rgb(0, 153,
Code values for red, green, and blue. 0)"
<!DOCTYPE html>
<html>
<head>
<title>
</title>
</head>
<body>
GeeksforGeeks!
</font>
<br>
GeeksforGeeks!
</font>
<br>
GeeksforGeeks!
</font>
</body>
Syntax:
<font face="font_family">
Attribute Values:
It contains a single value font_family which is used to specify the font
family. Several font family can be used by separating comma.
Example: The implementation of the font face attribute
<!DOCTYPE html>
<html>
<head>
<title>
</title>
</head>
<body>
GeeksforGeeks!
</font>
<br>
GeeksforGeeks!
</font>
<br>
<font size="6">
GeeksforGeeks!
</font>
</body>
</html>
Output:
HTML align Attribute in HTML is used to specify the alignment of the text
content of The Element. This attribute is used in all elements. The Align
attribute can also be set using the CSS property “text-align: ” or
in <img> “vertical-align: “. For horizontal alignment, use align with values
like “left,” “center,” or “right” within appropriate tags.
Syntax:
<element_name align="left | right | center | justify">
Attribute Values:
Attribute Values Description
<!DOCTYPE html>
<html>
<head>
<title>
HTML p align Attribute
</title>
</head>
<body>
<h1>GeeksforGeeks</h1>
<p align="left">
Left align content
</p>
<p align="center">
center align content
</p>
<p align="right">
Right align content
</p>
</body>
</html>
Output:
Hyperlink
HTML provides a feature called Links that allows users to navigate from page to page by clicking
on words, phrases and images. These HTML links are called hyperlinks. A hyperlink is a text or an
image and when we click on, we jump to another document. A webpage can contain various
links that takes us directly to other pages and even specific parts of a given page. Thus we can
create hyperlinks using text or images available on a webpage.
Hyperlinks allow visitors to navigate between Web sites.
Hyper Links are normally displayed as highlighted and underlined text. When you click on it, it
takes you to another page on the web. The <a> tag is used for creating hyperlinks. The syntax is
given as following,
• Absolute Link: These are links to another page outside of our web site. These links specify
the entire URL of the page:
<a HREF=http://www.annauniv.edu/>AU Web Site</a>
AU Web Site
• Relative Link: These are links to another page in our site so we do not have to specify the
entire URL.
<a HREF=“index.html”>Go back to main page</a>
HTML TABLES
HTML tables allow web developers to arrange data like text, images, links, other tables, etc. into
rows and columns of cells. Tables can also be used for organizing the layout of the web page
itself. These HTML tables can be created using the <table> tag in which the <tr> tag is used to
create table rows and <td> tag is used to create data cells. In simple, we can understand that the
HTML Table Element <table> represents data in two dimensions or more.
1. Table Row<TR></TR>.
4. Caption <CAPTION></CAPTION>.
The Table rows can be grouped into a head, foot, and body sections using the THEAD, TFOOT
and TBODY elements, respectively. Head section also called the header cell is defined with a
<thead> element that contains the header information such as column names.
The <thead> tag must be used as a child of a <table> element, after any <caption>, and
<colgroup> elements, and before any <tbody>, <tfoot>, and <tr> elements.
The Foot section is defined with a <tfoot> element are the footer rows that appears at the
bottom of the table. The purpose of this <thead> and <tfoot> elements are that when long tables
are printed, the head and foot information may be repeated on each page that contains table
data.
The Table body is defined with a <tbody> element. Otherwise they are called as data cells defined
with <td> element.
We can use at most one <thead> or <tfoot> but we can use multiple <tbody> elements in a table.
The caption tag is the descriptive title and used to provide a short description about the table's
purpose or it can be used to name the table.
Tables are divided into table rows with the <tr> tag. Table rows are divided into table data with
the <td> tag. A table row can also be divided into table headings with the <th> tag. By default, all
major browsers display table headings as bold and cantered:
TABLES ATTRIBUTES
• BGColor: Some browsers support background colors in a table.
• Width: We can specify the table width as an absolute number of pixels or a percentage of
the document width. We can set the width for the table cells as well.
• Border: We can choose a numerical value for the border width, which specifies the
border in pixels.
• CellSpacing: Cell Spacing represents the space between cells and is specified in pixels.
• CellPadding: Cell Padding is the space between the cell border and the cell contents and
is specified in pixels.
• Align: Tables can have left, right, or center alignment.
• Background: Background Image, will be titled in IE3.0 and above. BorderColor,
BorderColorDark.
<table border = "1" width = "40%" summary = "This table provides information about the price
of fruit">
<caption><strong>Price of Fruit</strong></caption>
<thead>
<tr>
<th>Fruit</th>
<th>Price</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Total</th>
<th>$3.75</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Apple</td>
<td>$0.25</td>
</tr>
<tr>
<td>Orange</td>
<td>$0.50</td>
</tr>
<tr>
<td>Banana</td>
<td>$1.00</td>
</tr>
<tr>
<td>Pineapple</td>
<td>$2.00</td>
</tr>
</tbody>
</table>
Table cell spacing represents the space between cells. cellpadding is the space between the cell
border and the cell contents.
Cells can span multiple columns and multiple rows with the colspan and rowspan attributes. In
order to make a cell span more than one column we can use the colspan attribute and to make a
cell span more than one row we can use the rowspan attribute.
Examples
<th colspan="2">Name</th>
<td rowspan="2">Fishing</td>
• A frameset partitions a web browser window so that multiple web documents can be
displayed simultaneously.
• The <frameset> element replaces the <body> element that is used in non-frame
documents.
Columns Example
The Figure 6.3 shows how the frames are divided into columns by specifying the cols attribute.
FRAME ATTRIBUTES
Let us now consider the following example to explain about the frame attributes.
<frameset cols="140,*">
<frame name="navF" src="navigation.html">
<frame name="mainF" src="intro.html">
</frameset>
The name attribute uniquely identifies the frame. It is used as the target in an anchor (<a>)
element. The src attribute specifies the web page to be placed in the frame initially and it may
subsequently be overwritten also.
The scrolling attribute ("auto", "yes", "no") specifies whether the frame is to have scroll bars.
The frameborder attribute ("0", "1") specifies whether the frame is to have a border.