HTML Lists Notes
HTML Lists Notes
HTML offers web authors three ways for specifying lists of information. All lists must contain
one or more list elements. Lists may contain:
<ul> - An unordered list. This will list items using plain bullets.
<ol> - An ordered list. This will use different schemes of numbers to list your items.
<dl> - A definition list. This arranges your items in the same way as they are arranged in
a dictionary.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Unordered List</title>
</head>
<body>
<ul>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
Beetroot
Ginger
Potato
Radish
<ul type="square">
<ul type="disc">
<ul type="circle">
1
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Unordered List</title>
</head>
<body>
<ul type="square">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
Beetroot
Ginger
Potato
Radish
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Unordered List</title>
</head>
<body>
<ul type="disc">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
Beetroot
Ginger
Potato
Radish
2
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Unordered List</title>
</head>
<body>
<ul type="circle">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
o Beetroot
o Ginger
o Potato
o Radish
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
3
1. Beetroot
2. Ginger
3. Potato
4. Radish
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type="1">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
1. Beetroot
2. Ginger
3. Potato
4. Radish
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
4
</head>
<body>
<ol type="I">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
I. Beetroot
II. Ginger
III. Potato
IV. Radish
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type="i">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
i. Beetroot
ii. Ginger
iii. Potato
iv. Radish
Example
<!DOCTYPE html>
<html>
<head>
5
<title>HTML Ordered List</title>
</head>
<body>
<ol type="A">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
A. Beetroot
B. Ginger
C. Potato
D. Radish
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type="a">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
a. Beetroot
b. Ginger
c. Potato
d. Radish
6
<ol type="1" start="4"> - Numerals starts with 4.
<ol type="I" start="4"> - Numerals starts with IV.
<ol type="i" start="4"> - Numerals starts with iv.
<ol type="a" start="4"> - Letters starts with d.
<ol type="A" start="4"> - Letters starts with D.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type="i" start="4">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
iv. Beetroot
v. Ginger
vi. Potato
vii. Radish
Example
<!DOCTYPE html>
<html>
7
<head>
<title>HTML Definition List</title>
</head>
<body>
<dl>
<dt><b>HTML</b></dt>
<dd>This stands for Hyper Text Markup Language</dd>
<dt><b>HTTP</b></dt>
<dd>This stands for Hyper Text Transfer Protocol</dd>
</dl>
</body>
</html>
HTML
This stands for Hyper Text Markup Language
HTTP
This stands for Hyper Text Transfer Protocol
8
HTML Tables
The HTML tables allow web authors to arrange data like text, images, links, other tables, etc.
into rows and columns of cells.
The HTML tables are 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.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Tables</title>
</head>
<body>
<table border="1">
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
</table>
</body>
</html>
Here border is an attribute of <table> tag and it is used to put a border across all the cells. If you
do not need a border then you can use border="0".
Table Heading
Table heading can be defined using <th> tag. This tag will be put to replace <td> tag, which is
used to represent actual data cell. Normally you will put your top row as table heading as shown
below, otherwise you can use <th> element in any row.
Example
9
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Header</title>
</head>
<body>
<table border="1">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
<tr>
<td>Shabbir Hussein</td>
<td>7000</td>
</tr>
</table>
</body>
</html>
Name Salary
Ramesh Raman 5000
Shabbir Hussein 7000
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Cellpadding</title>
</head>
<body>
<table border="1" cellpadding="5" cellspacing="5">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
10
<tr>
<td>Shabbir Hussein</td>
<td>7000</td>
</tr>
</table>
</body>
</html>
Name Salary
Ramesh Raman 5000
Shabbir Hussein 7000
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Colspan/Rowspan</title>
</head>
<body>
<table border="1">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr><td rowspan="2">Row 1 Cell 1</td><td>Row 1 Cell 2</td><td>Row 1 Cell
3</td></tr>
<tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr>
<tr><td colspan="3">Row 3 Cell 1</td></tr>
</table>
</body>
</html>
11
Tables Backgrounds
You can set table background using one of the following two ways:
bgcolor attribute - You can set background color for whole table or just for one cell.
background attribute - You can set background image for whole table or just for one
cell.
You can also set border color also using bordercolor attribute.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Background</title>
</head>
<body>
<table border="1" bordercolor="green" bgcolor="yellow">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr><td rowspan="2">Row 1 Cell 1</td><td>Row 1 Cell 2</td><td>Row 1 Cell
3</td></tr>
<tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr>
<tr><td colspan="3">Row 3 Cell 1</td></tr>
</table>
</body>
</html>
Here is an example of using background attribute. Here we will use an image available in
/images directory.
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Background</title>
</head>
<body>
<table border="1" bordercolor="green" background="/images/[Link]">
12
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr><td rowspan="2">Row 1 Cell 1</td><td>Row 1 Cell 2</td><td>Row 1 Cell
3</td></tr>
<tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr>
<tr><td colspan="3">Row 3 Cell 1</td></tr>
</table>
</body>
</html>
This will produce following result. Here background image did not apply to table's header.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Width/Height</title>
</head>
<body>
<table border="1" width="400" height="150">
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
</table>
</body>
</html>
13
Row 2, Column 1 Row 2, Column 2
Table Caption
The caption tag will serve as a title or explanation for the table and it shows up at the top of the
table. This tag is deprecated in newer version of HTML/XHTML.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Caption</title>
</head>
<body>
<table border="1" width="100%">
<caption>This is the caption</caption>
<tr>
<td>row 1, column 1</td><td>row 1, columnn 2</td>
</tr>
<tr>
<td>row 2, column 1</td><td>row 2, columnn 2</td>
</tr>
</table>
</body>
</html>
The three elements for separating the head, body, and foot of a table are:
A table may contain several <tbody> elements to indicate different pages or groups of data. But
it is notable that <thead> and <tfoot> tags should appear before <tbody>
14
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table</title>
</head>
<body>
<table border="1" width="100%">
<thead>
<tr>
<td colspan="4">This is the head of the table</td>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="4">This is the foot of the table</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</tbody>
</table>
</body>
</html>
Nested Tables
You can use one table inside another table. Not only tables you can use almost all the tags inside
table data tag <td>.
Example
Following is the example of using another table and other tags inside a table cell.
<!DOCTYPE html>
<html>
<head>
<title>HTML Table</title>
15
</head>
<body>
<table border="1" width="100%">
<tr>
<td>
<table border="1" width="100%">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
<tr>
<td>Shabbir Hussein</td>
<td>7000</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Name Salary
Ramesh Raman 5000
Shabbir Hussein 7000
16
The <style> element does not represent actual content for the user. Rather, it is used for styling
the content.
Syntax
The <style> tag is written as <style></style> with the style sheet inserted between the start
and end tags.
Like this:
<style>
Styles here...
</style>
You can use the type attribute to specify the style sheet language. In HTML 4 this is a required
attribute. From HTML5 it is optional. Like this:
<style type="text/css">
Styles here...
</style>
<!DOCTYPE html>
<html>
<head>
<title>Table Example</title>
<style>
table, th, td {
border: 1px solid orange;
}
</style>
</head>
<body>
<table>
<tr>
<th>Table Header</th>
<th>Table Header</th>
<th>Table Header</th>
</tr>
<tr>
<td>Table cell</td>
<td>Table cell</td>
<td>Table cell</td>
</tr>
<tr>
<td>Table cell</td>
<td>Table cell</td>
<td>Table cell</td>
</tr>
17
</table>
</body>
</html>
HTML Frames
18
HTML frames are used to divide your browser window into multiple sections where each section
can load a separate HTML document. A collection of frames in the browser window is known as
a frameset. The window is divided into frames in a similar way the tables are organized: into
rows and columns.
Disadvantages of Frames
There are few drawbacks with using frames, so it's never recommended to use frames in your
webpages:
Some smaller devices cannot cope with frames often because their screen is not big
enough to be divided up.
Sometimes your page will be displayed differently on different computers due to different
screen resolution.
The browser's back button might not work as the user hopes.
There are still few browsers that do not support frame technology.
Creating Frames
To use frames on a page we use <frameset> tag instead of <body> tag. The <frameset> tag
defines how to divide the window into frames. The rows attribute of <frameset> tag defines
horizontal frames and cols attribute defines vertical frames. Each frame is indicated by <frame>
tag and it defines which HTML document shall open into the frame.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Frames</title>
</head>
<frameset rows="10%,80%,10%">
<frame name="top" src="/html/top_frame.htm" />
<frame name="main" src="/html/main_frame.htm" />
<frame name="bottom" src="/html/bottom_frame.htm" />
<noframes>
<body>
Your browser does not support frames.
</body>
</noframes>
</frameset>
</html>
19
Example
Let's put above example as follows, here we replaced rows attribute by cols and changed their
width. This will create all the three frames vertically:
<!DOCTYPE html>
<html>
<head>
<title>HTML Frames</title>
</head>
<frameset cols="25%,50%,25%">
<frame name="left" src="/html/top_frame.htm" />
<frame name="center" src="/html/main_frame.htm" />
<frame name="right" src="/html/bottom_frame.htm" />
<noframes>
<body>
Your browser does not support frames.
</body>
</noframes>
</frameset>
</html>
20
Attribute Description
specifies how many columns are contained in the frameset and the size of each
column. You can specify the width of each column in one of four ways:
Absolute values in pixels. For example to create three vertical frames, use
cols="100, 500,100".
A percentage of the browser window. For example to create three vertical
frames, use cols="10%, 80%,10%".
cols Using a wildcard symbol. For example to create three vertical frames, use
cols="10%, *,10%". In this case wildcard takes remainder of the window.
As relative widths of the browser window. For example to create three
vertical frames, use cols="3*,2*,1*". This is an alternative to percentages.
You can use relative widths of the browser window. Here the window is
divided into sixths: the first column takes up half of the window, the second
takes one third, and the third takes one sixth.
This attribute works just like the cols attribute and takes the same values, but it is
used to specify the rows in the frameset. For example to create two horizontal
rows
frames, use rows="10%, 90%". You can specify the height of each row in the same
way as explained above for columns.
This attribute specifies the width of the border of each frame in pixels. For example
border
border="5". A value of zero means no border.
This attribute specifies whether a three-dimensional border should be displayed
frameborder between frames. This attrubute takes value either 1 (yes) or 0 (no). For example
frameborder="0" specifies no border.
This attribute specifies the amount of space between frames in a frameset. This can
framespacing take any integer value. For example framespacing="10" means there should be 10
pixels spacing between each frames.
Attribute Description
This attribute is used to give the file name that should be loaded in the frame. Its
src value can be any URL. For example, src="/html/top_frame.htm" will load an
HTML file available in html directory.
This attribute allows you to give a name to a frame. It is used to indicate which
frame a document should be loaded into. This is especially important when you
name
want to create links in one frame that load pages into an another frame, in which
case the second frame needs a name to identify itself as the target of the link.
This attribute specifies whether or not the borders of that frame are shown; it
frameborder overrides the value given in the frameborder attribute on the <frameset> tag if one
is given, and this can take values either 1 (yes) or 0 (no).
marginwidth This attribute allows you to specify the width of the space between the left and
21
right of the frame's borders and the frame's content. The value is given in pixels.
For example marginwidth="10".
This attribute allows you to specify the height of the space between the top and
marginheight bottom of the frame's borders and its contents. The value is given in pixels. For
example marginheight="10".
By default you can resize any frame by clicking and dragging on the borders of a
noresize frame. The noresize attribute prevents a user from being able to resize the frame.
For example noresize="noresize".
This attribute controls the appearance of the scrollbars that appear on the frame.
scrolling This takes values either "yes", "no" or "auto". For example scrolling="no" means it
should not have scroll bars.
This attribute allows you to provide a link to another page containing a long
longdesc description of the contents of the frame. For example
longdesc="[Link]"
So you must place a <body> element inside the <noframes> element because the <frameset>
element is supposed to replace the <body> element, but if a browser does not understand
<frameset> element then it should understand what is inside the <body> element which is
contained in a <noframes> element.
You can put some nice message for your user having old browsers. For example Sorry!! your
browser does not support [Link] shown in the above example.
Let's see following example where a [Link] file has following code:
<!DOCTYPE html>
<html>
<head>
<title>HTML Target Frames</title>
</head>
<frameset cols="200, *">
<frame src="/html/[Link]" name="menu_page" />
<frame src="/html/[Link]" name="main_page" />
<noframes>
<body>
Your browser does not support frames.
</body>
22
</noframes>
</frameset>
</html>
Here we have created two columns to fill with two frames. The first frame is 200 pixels wide and
will contain the navigation menubar implemented by [Link] file. The second column fills in
remaining space and will contain the main part of the page and it is implemented by [Link]
file. For all the three links available in menubar, we have mentioned target frame as main_page,
so whenever you click any of the links in menubar, available link will open in main_page.
<!DOCTYPE html>
<html>
<body bgcolor="#4a7d49">
<a href="[Link] target="main_page">Google</a>
<br /><br />
<a href="[Link] target="main_page">Microsoft</a>
<br /><br />
<a href="[Link] target="main_page">BBC News</a>
</body>
</html>
<!DOCTYPE html>
<html>
<body bgcolor="#b5dcb3">
<h3>This is main page and content from any link will be displayed here.</h3>
<p>So now click any link and see the result.</p>
</body>
</html>
Now you can try to click links available in the left panel and see the result. The target attribute
can also take one of the following values:
Option Description
_self Loads the page into the current frame.
_blank Loads a page into a new browser [Link] a new window.
Loads the page into the parent window, which in the case of a single frameset is the
_parent
main browser window.
23
_top Loads the page into the browser window, replacing any current frames.
targetframe Loads the page into a named targetframe.
Examples of frames
EXAMPLES
top
bottom
<frameset rows="16%,84%">
<frame src="[Link]" name="top">
<frame src="[Link]" name="bottom">
</frameset>
tr
tl
bottom
<frameset rows="16%,84%">
<frameset cols="50%,50%">
<frame src="[Link]" name="tl">
<frame src="[Link]" name="tr">
</frameset>
<frame src="[Link]" name="bottom">
</frameset>
top
24
left right
<frameset rows="16%,84%">
<frame src="[Link]" name="top">
<frameset cols="50%,50%">
<frame src="[Link]" name="left">
<frame src="[Link]" name="right">
</frameset>
</frameset>
topleft topright
botleft botright
topleft topright
brtl brtr
botleft botrbot
25
</frameset>
</frameset>
topleft topright
botleft botright
topleft topright
botleft botright
HTML frames allow authors to present documents in multiple views, which may be independent
windows or subwindows. Multiple views offer designers a way to keep certain information
visible, while other views are scrolled or replaced. For example, within the same window, one
frame might display a static banner, a second a navigation menu, and a third the main document
that can be scrolled through or replaced by navigating in the second frame.
26
<FRAMESET cols="20%, 80%">
<FRAMESET rows="100, 200">
<FRAME src="contents_of_frame1.html">
<FRAME src="contents_of_frame2.gif">
</FRAMESET>
<FRAME src="contents_of_frame3.html">
<NOFRAMES>
<P>This frameset document contains:
<UL>
<LI><A href="contents_of_frame1.html">Some neat contents</A>
<LI><IMG src="contents_of_frame2.gif" alt="A neat image">
<LI><A href="contents_of_frame3.html">Some other neat contents</A>
</UL>
</NOFRAMES>
</FRAMESET>
</HTML>
---------------------------------------
| | |
| | |
| Frame 1 | |
| | |
| | |
|---------| |
| | Frame 3 |
| | |
| | |
| | |
| Frame 2 | |
| | |
| | |
| | |
| | |
---------------------------------------
If the user agent can't display frames or is configured not to, it will render the contents of the
NOFRAMES element.
The FRAMESET section of a document specifies the layout of views in the main user agent
window. In addition, the FRAMESET section can contain a NOFRAMES element to provide
alternate content for user agents that do not support frames or are configured not to display
frames.
27
Elements that might normally be placed in the BODY element must not appear before the first
FRAMESET element or the FRAMESET will be ignored.
Attribute definitions
rows = multi-length-list[CN]
This attribute specifies the layout of horizontal frames. It is a comma-separated list of pixels,
percentages, and relative lengths. The default value is 100%, meaning one row.
cols = multi-length-list[CN]
This attribute specifies the layout of vertical frames. It is a comma-separated list of pixels,
percentages, and relative lengths. The default value is 100%, meaning one column.
The FRAMESET element specifies the layout of the main user window in terms of rectangular
subspaces.
Setting the rows attribute defines the number of horizontal subspaces in a frameset. Setting the
cols attribute defines the number of vertical subspaces. Both attributes may be set
simultaneously to create a grid.
28
If the rows attribute is not set, each column extends the entire length of the page. If the cols
attribute is not set, each row extends the entire width of the page. If neither attribute is set, the
frame takes up exactly the size of the page.
Frames are created left-to-right for columns and top-to-bottom for rows. When both attributes are
specified, views are created left-to-right in the top row, left-to-right in the second row, etc.
The first example divides the screen vertically in two (i.e., creates a top half and a bottom half).
The next example creates three columns: the second has a fixed width of 250 pixels (useful, for
example, to hold an image with a known size). The first receives 25% of the remaining space and
the third 75% of the remaining space.
<FRAMESET cols="1*,250,3*">
...the rest of the definition...
</FRAMESET>
For the next example, suppose the browser window is currently 1000 pixels high. The first view
is allotted 30% of the total height (300 pixels). The second view is specified to be exactly 400
pixels high. This leaves 300 pixels to be divided between the other two frames. The fourth
frame's height is specified as "2*", so it is twice as high as the third frame, whose height is only
"*" (equivalent to 1*). Therefore the third frame will be 100 pixels high and the fourth will be
200 pixels high.
<FRAMESET rows="30%,400,*,2*">
...the rest of the definition...
</FRAMESET>
Absolute lengths that do not sum to 100% of the real available space should be adjusted by the
user agent. When underspecified, remaining space should be allotted proportionally to each
view. When overspecified, each view should be reduced according to its specified proportion of
the total space.
29
In the following example, the outer FRAMESET divides the available space into three equal
columns. The inner FRAMESET then divides the second area into two rows of unequal height.
Authors may share data among several frames by including this data via an OBJECT element.
Authors should include the OBJECT element in the HEAD element of a frameset document and
name it with the id attribute. Any document that is the contents of a frame in the frameset may
refer to this identifier.
The following example illustrates how a script might refer to an OBJECT element defined for an
entire frameset:
30
The next example features nested FRAMESET elements to define two frames in the first row
and one frame in the second row:
<FRAMESET ROWS="*,100">
<FRAMESET COLS="40%,*">
<FRAME NAME="Menu" SRC="[Link]" TITLE="Menu">
<FRAME NAME="Content" SRC="[Link]" TITLE="Content">
</FRAMESET>
<FRAME NAME="Ad" SRC="[Link]" TITLE="Advertisement">
<NOFRAMES>
<BODY>
<H1>Table of Contents</H1>
<UL>
<LI>
<A HREF="reference/html40/">HTML 4 Reference</A>
</LI>
<LI>
<A HREF="reference/wilbur/">HTML 3.2 Reference</A>
</LI>
<LI>
<A HREF="reference/css/">CSS Guide</A>
</LI>
</UL>
<P>
<IMG SRC="[Link]" ALT="Ad: Does your bank charge too much?">
</P>
</BODY>
</NOFRAMES>
</FRAMESET>
HTML LINKS
You can create a link in an HTML page to another document, by using the HREF attribute. You
can use HREF attribute to links within your own directory tree limit or you can links to external
websites too.
TYPES OF LINKS
31
Internal Links
When you link your pages within your own directory tree limit is called Internal Link. While a
user browsing your website , the browser is already in your directory, then you can points links
from the current directory and don ' t need to specify a full URL path.
If you are in HTML directory of [Link] , and you want to link an html page
tables/[Link] from HTML directory you can code like this
Here in this case you can avoid a full URL path like :
If all your html files are in the same directory , you can give just file name and extension in
HREF attribute.
External Links
e.g. If you want to create an external link from your website to [Link] help page, you can code
like this:
In order to create an external link to another web site, you need to know the other web site URL
with full path.
The src attribute identifies an image by a URL. The image defined by the URL is retrieved by
the browser and inserted into the document when the page loads. There are three different kinds
of URLs that can be used in the src attribute:
32
Relative vs. absolute path links
This is a link with relative path URL:
Text Link
Absolute
Text Link
TYPES OF URLS
Absolute URLs
Absolute
This refers to a URL where the full path is provided. For example:
Relative URLs
This refers to a URL where the path, relative to the current location, is provided.
A relative URL does not include the domain name, and is relative to either the current
page, or the current domain. If you begin the URL without a slash ( / ), it will be
relative to the current page. If you begin with a slash, it will be relative to the domain.
It is almost always the best idea to use source URLs which are relative to the domain,
not the page. They will not break if the page content is moved or copied. Additionally,
when linking to images on your own site, it is almost always best to use relative URLs
rather than absolute URLs. This way, the URLs won't break when you change
33
domains (which will happen automatically if you use a development or staging server
in addition to your production one).
<imgsrc="/wp-content/uploads/[Link]">
Root relative
This refers to a URL where the path, relative to the domain's root, is provided.
Example headline
When pressing the above link the browser will jump to the heading below, with this code:
Example headline
Some text...
34
HTML link code generator
When pressing the link the browser will jump to the html-link page section that has this code:
Download link is a link that is used to download a file from the server to the browser's directory
on the local disk.
Download File
The web browser requires a default e-mail client software installed on his computer in order to
activate the e-mail client.
If you have Microsoft Outlook, for example as your default mail client, pressing a mailto link
will open a new mail window.
35
How to create mailto link in HTML
The mailto link is written like regular link with extra parameters inside the href attribute:
Parameter Description
mailto examples
Mail to email address
Send mail
36
Mail to email address with subject
<a href="[Link]
mail with subject</a>
37
Mail to email address with cc, bcc, subject and body
<a href="[Link]
cc=name2@[Link]&bcc=name3@[Link]
&subject=The%20subject%20of%20the%20email
&body=The%20body%20of%20the%20email">
Send mail with cc, bcc, subject and body</a>
38
How to add spaces in the mail's subject or body
You can add spaces by writing %20 in the text of the subject or body.
<a href="[Link]
%20message%20body">Send mail</a>
To:
39
Cc:
Bcc:
Subject:
Body:
Without javascript:
<form action="../[Link]">
<input type="submit" value="This is a button link">
</form>
40
With javascript:
Link color
Changing link color is done with css styling:
HTML Images
Images are very important to beautify as well as to depict many complex concepts in simple way
on your web page. This tutorial will take you through simple steps to use images in your web
pages.
41
Adding pictures to the pages of your website can often make them more pleasing to the eye and
convey information better than using text alone. This process is accomplished by using HTML
code and an image file. The file can be from a different web page or stored on a web server.
Src - The source attribute indicates the location of the image. You may use a relative path
if the image is on the same server as your site, but images from another site require
absolute paths.
Alt - The alternate text attribute is a written description of the image.
Width - The width of the image.
Height - The height of the image.
An optional attribute is Border, which allows you to specify a border around the image. The
border attribute is defined in pixel size. For example, using border=1 in the <img> tag means the
border around the image would be 1 pixel wide.
Note: The Border attribute has been deprecated in HTML5 and is not supported.
Insert Image
You can insert any image in your web page by using <img> tag. Following is the simple syntax
to use this tag.
The <img> tag is an empty tag, which means that it can contain only list of attributes and it has
no closing tag.
Example
To try following example, let's keep our HTML file [Link] and image file [Link] in the same
directory:
<!DOCTYPE html>
<html>
<head>
<title>Using Image in Webpage</title>
</head>
<body>
<p>Simple Image Insert</p>
<imgsrc="/html/images/[Link]"alt="Test Image"/>
</body>
</html>
42
You can use PNG, JPEG or GIF image file based on your comfort but make sure you specify
correct image file name in src attribute. Image name is always case sensitive.
The alt attribute is a mandatory attribute which specifies an alternate text for an image, if the
image cannot be displayed.
Example
<!DOCTYPE html>
<html>
<head>
<title>Using Image in Webpage</title>
</head>
<body>
<p>Simple Image Insert</p>
<imgsrc="/html/images/[Link]"alt="Test Image"/>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<head>
<title>Set Image Width and Height</title>
</head>
<body>
<p>Setting image width and height</p>
<imgsrc="/html/images/[Link]"alt="Test Image"width="150"height="100"/>
</body>
</html>
43
By default image will have a border around it, you can specify border thickness in terms of
pixels using border attribute. A thickness of 0 means, no border around the picture.
Example
<!DOCTYPE html>
<html>
<head>
<title>Set Image Border</title>
</head>
<body>
<p>Setting image Border</p>
<imgsrc="/html/images/[Link]"alt="Test Image"border="3"/>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<head>
<title>Set Image Alignment</title>
</head>
<body>
<p>Setting image Alignment</p>
<imgsrc="/html/images/[Link]"alt="Test Image"border="3"align="right"/>
</body>
</html>
Examples
The following examples show the actual HTML used to add the image at the top of this page.
They may be inserted anywhere in the body of your page. The first has a shorter URL because
the image is stored on our server; the second is how you would link to our image.
Example 1:
44
<imgsrc="pictures/[Link]" alt="3D HTML Letters" width="317" height="218">
Example 2:
FORMATS OF IMAGES
The most common image formats to use for pictures, photos, logos, and other images is JPEG,
GIF, and PNG. Other image formats that are not widely supported such as BMP may not work in
all browsers.
45