Chapter Two HTML: Internet Programming Compiled By:tadesse K
Chapter Two HTML: Internet Programming Compiled By:tadesse K
CHAPTER TWO
HTML
11/16/2016
2.1 Introduction
2
What is HTML
HTML stands for Hypertext Markup Language.
HTML Tags
HTML is written in the form of HTML elements consisting of
HTML tags surrounded by angle brackets (e.g. <html>).
HTML tags Syntax: <tagname>content</tagname>
The first tag in a pair is the start tag, the second tag is the end
tag
You can also refer to them as opening tags and closing tags.
Web browsers
While a web developer uses the HTML tags to create the web
page, software is required to interpret tags and display the
information.
The software is web browser software.
The purpose of a web browser(Chrome, IE, Firefox, Safari)is to
read HTML documents and display them as web pages.
The browser does not display the HTML tags, but uses them to
determine how to display document.
HTML elements are written with a start tag, with an end tag, with the
content in between:<tagname>content</tagname>
The HTML element is everything from the start tag to the end tag.
Example: <p>Paragraph</p>
Nested HTML Elements: elements can contain elements.
Example: <!DOCTYPE html>
<html>
<body>
<h1> Heading one</h1>
<p>This is a paragraph.</p>
</body> </html>
Internet programming Compiled by:Tadesse K. 11/16/2016
2.3 HTML Elements….
7
The total code is divided into two parts and both the parts are
kept inside <html> tag.
Our page should start with <html> and end with </html>.
The first part inside this html tags is the head and it starts with
<head> and ends with </head>.
The second part starts with <body> and ends with </body>
tag.
Inside the <body> tag we keep all our content which we want
to display to our web page users.
Whatever we place in <body> will be displayed by the
browser to the web users.
Internet programming Compiled by:Tadesse K. 11/16/2016
2.4 HTML Page Structure( HTML, HEAD,
TITLE and BODY Tags)…….
10
<BODY> </BODY>
This is where we place our content for our visitors.
What we place here will be displayed to our visitors.
The style and other formatting of the text and what you
could do to fill the content of the web page will discuss in
different sections.
A <body> element may contain anything from a couple
of paragraphs under a heading to more complicated
layouts containing forms and tables.
Internet programming Compiled by:Tadesse K. 11/16/2016
2.4 HTML Page Structure( HTML, HEAD,
TITLE and BODY Tags)…….
11
<HEAD> </HEAD>
The web page should have only one head tag.
The head tag starts with <head> and ends with </head>.
The text or tags that are inside the head tag will not be displayed in
the browser window.
One of the important tags which is put inside <head> is <title>
</title> tag.
Title tags are used to give title to the browser window.
Title tags are also important for our search engine point of view.
We should keep most important keywords inside the title tag.
The following tags can be added to the head section: <title>,
<style>, <meta>, <link>,<script>, <noscript>, and <base>.
Internet programming Compiled by:Tadesse K. 11/16/2016
2.4 HTML Page Structure( HTML, HEAD,
TITLE and BODY Tags)…….
12
Example:
<html>
<head>
<title> Nuclear Energy </title>
</head>
<body>
Nuclear energy is one of the clean environment friendly
energy source.
</body>
</html>
Always Quote Attribute Values :when the attribute value itself contains
double quotes, it is necessary to use single quotes:
Example: <p title='John "ShotGun" Nelson'>Or vice versa:
Example: <p title="John 'ShotGun' Nelson">
<html> attribute
Setting HTML Language
The HTML lang attribute can be used to declare the language of a
Web page or a portion of a Web page.
This is meant to assist search engines and browsers.
<html lang=“om">
<head>
<title>Setting Language</title>
</head>
<body>
This web page in Afan Oromo
</body>
</html>
<body bgcolor=”#00FF00”>
Background Image
We can use a background picture for web page instead of
background color.
You must have an image to do this.
Then you can use background attribute of <BODY> tag as follows:
<BODY BACKGROUND="image1.gif">
Text Color
We can also set the text color of the web page just like background
color.
We use text attribute of <BODY> to do this.
Example:
<HTML>
<HEAD>
<TITLE>Page with Back Color</TITLE>
</HEAD>
<BODY bgcolor="yellow" text="#FF0000">
Page with yellow back color and red text color
</BODY>
</HTML>
vlink: Sets a color for visited links - that is, for linked text that you
have already clicked on.
<html>
<head>
<title> Link Colors </title>
</head>
<body alink="#00A000“ link="#00FF00" vlink="#0000FF">
<a href="first.html">first page</a><br>
<a href="first1.html"> second page</a><br>
</body>
</html> Internet programming Compiled by:Tadesse K. 11/16/2016
2.5 HTML Tag Attributes…
25
Meta Tag
The <meta> tag provides metadata about the HTML document.
Metadata is data (information) about data.
Metadata will not be displayed on the page, but will be machine
parsable.
Meta elements are used to specify page description, keywords,
author of the document, last modified, and other metadata.
The metadata can be used by browsers (how to display content or
reload page), search engines (keywords), or other web services.
<meta> tags always goes inside the <head> element.
Metadata is always passed as name/value pairs.
The content attribute must be defined if the name or the http-equiv
attribute is defined.
if none of these are defined, the content attribute cannot be
defined. Internet programming Compiled by:Tadesse K. 11/16/2016
2.5 HTML Tag Attributes…
26
description
generator
keywords
content text Gives the value associated with the http-
equiv or name attribute
Internet programming Compiled by:Tadesse K. 11/16/2016
2.5 HTML Tag Attributes…
27
page.
Today, search engines no longer depend on keywords meta
engines, like Yahoo! and Bing, while Google will fall back on
this tag when information about the page itself is requested.
The structure is as follows:
This can be used by caches to determine when to fetch a fresh copy of the
associated document.
Heading tags are block tags, and you must specify opening
and closing tags.
Example:
<body>
<h1>this is heading level 1.</h1>
<hr>
<h2>this is heading level 2.</h2>
<h3>this is heading level 3.</h3>
<h4>this is heading level 4.</h4>
<h5>this is heading level 5.</h5>
<h6>this is heading level 6.</h6>
</body> Internet programming Compiled by:Tadesse K. 11/16/2016
2.6 HTML Headings…
35
The <font> tag is used to add font type, size, and color to the
text on your site.
The font tag is has three attributes
size,
color, and
face
Font Size:
You can set the size of your font with size attribute.
Example:
<font size="1">Font size=1</font>
<font size="2">Font size=2</font>
<font size="3">Font size=3</font>
<font size="4">Font size=4</font>
<font size="5">Font size=5</font>
<font size="6">Font size=6</font>
<font size="7">Font size=7</font>
Internet programming Compiled by:Tadesse K. 11/16/2016
2.8 HTML Fonts…
41
<font size="+n">
<font size="-n">
This specifies how many sizes larger or how many sizes smaller than
the preset font size should be.
Example:
Font Face:
You can set any font you like using face attribute
But be aware that if the user viewing the page doesn't have the font
installed, they will not be able to see it.
Instead they will default to Times New Roman of your font with size
attribute.
Example:
A visitor will only be able to see your font if they have that font
installed on their computer.
So, it is possible to specify two or more font face alternatives
syntax: style="property:value"
NB: The property is a CSS property. The value is a CSS value.
Example:<p style="color:red">This is a paragraph.</p>
Font Color:
You can set any font color you like using color attribute.
You can specify the color that you want by either the color name or
hexadecimal code for that color.
Check a complete list of HTML Color Name with Codes.
Example:
<basefont> settings.
The attributes that the <basefont> element takes are exactly
Example:
<basefont face="arial, verdana, sans-serif" size="2" color="#ff0000">
<p>This is the page's default font.</p>
<h2>Example of the <basefont> Element</h2>
<p><font size="+2" color="darkgray">Here is some darkgray text two sizes
larger</font></p>
<p><font face="courier" size="-1" color="#000000">Here is a courier font,
a size smaller, in black</font></p>
HTML Text Alignment
The text-align property defines the horizontal text alignment for an HTML
element:
Example: <h1 style="text-align:center">Centered Heading</h1>
NB:The <center> tag, supported in older versions of HTML, is not valid in
HTML5
Internet programming Compiled by:Tadesse K. 11/16/2016
2.9 HTML Text Formatting Elements
49
In HTML, there are many tags that you can use to enhance
and change the look of the text.
You can make text bold, italicized, or underlined; these
are just some of the presentational options available to
indicate how text can appear in HTML.
Bold Text - The <b> Element:
Anything that appears in a <b>...</b> element is
displayed in bold.
The <b> tag makes text to be displayed in bold face.
Internet programming Compiled by:Tadesse K. 11/16/2016
2.9 HTML Text Formatting Elements…
50
Example:
<p>The use nuclear energy needs <b> safety caution
</b> because of the associated danger.</p>
This will produce following result:
Example:
<p><var>E = m c<sup>2</sup></var></p>
Internet programming Compiled by:Tadesse K. 11/16/2016
2.9 HTML Text Formatting Elements…
53
You can also use <br /> which does the same.
Example
Hello<br>
You come most carefully upon your hour.<br />
Thanks<br>
Mahnaz
This will produce following result:
Hello
You come most carefully upon your hour.
Thanks
Mahnaz
Internet programming Compiled by:Tadesse K. 11/16/2016
2.9 HTML Text Formatting Elements…
56
<pre>
function testFunction( int a, int b ){
int sum = a + b;
alert (sum);
return;
}
Internet programming Compiled by:Tadesse K. 11/16/2016
</pre>
2.9 HTML Text Formatting Elements…
57
For example you may want to give a line between two paragraphs as
follows:
<p>This is paragraph one and should be on top</p>
<hr>
<p>This is paragraph two and should be at bottom</p>
Example:
<html>
<head>
<title>Formatting Tags</title>
</head>
<body>
<font size="5">
<p> The chemical formula for water is H<sub>2</sub>O </p>
<p> Solve 5X<sup>2</sup>+6X+10 </p>
<p>The following word uses a <small>small</small> typeface.</p>
<p>The following word uses a <big>big</big> typeface.</p>
</font>
</body>
</html> Internet programming Compiled by:Tadesse K. 11/16/2016
2.9 HTML Text Formatting Elements…
62
The <bdo> tag allows you to specify the text direction and
Tag Description
<em> Renders as emphasized text
<strong> Renders as strong (highlighted) text
<dfn> Defines a definition term
<code> Defines computer code text
<samp> Defines sample output from computer code
<kbd> Defines keyboard text
<var> Defines a variable part of a text
<cite> Defines a citation
<abbr> Defines an abbreviation
<acronym> Defines an acronym
<q> Defines a short quotation.
Internet programming Compiled by:Tadesse K. 11/16/2016
<blockquote> To quote a passage from another source
2.9 HTML Text Formatting Elements…
66
<html>
<head> <title>HTML Tags</title>
</head>
<body>
<abbr title="World Health Organization">WHO</abbr> reports that malaria epidemic is
increasing. <br>
Two <acronym title="North Atlantic Treaty Organization">NATO</acronym> troops are killed in
Afghanistan. <br>
<em>Emphasized text</em> <br>
<strong>Strong text</strong> <br>
<dfn>Definition term</dfn> <br>
<code>Computer code text</code> <br>
<samp>Sample computer code text</samp> <br>
<kbd>Keyboard text</kbd> <br>
<var>Variable</var> <br>
<cite>Citation</cite> <br>
</body>
</html> Internet programming Compiled by:Tadesse K. 11/16/2016
2.9 HTML Text Formatting Elements…
67
Anything between the opening <a> tag and the closing </a>
tag becomes part of the link.
The <a> tag can be used in two ways:
Here is an example:
HTML document.
Bookmarks are invisible to the reader.
If you place the cursor over the link, you will see the text in the title
attribute.
Example:
Linking to email
It is also possible to make a link to an e-mail address.
Linking to email
It is also possible to make a link to an e-mail address.
attribute.
Example:
Image Floating
You can let an image float to the left or right of a paragraph:
Example:<p><img src="smiley.gif" alt="Smiley face"
style="float:left;width:42px;height:42px">A paragraph with an image. The
image floats to the left of the text.</p>
The align attribute
The align attribute sets horizontal alignment of the image and takes
value either left, right or center.
Example:
Example:
<html>
<head>
<title>Testing HTML</title>
</head>
<body>
Just checking img tag.
<img src="coffee.png" alt="Highland coffee" align="left"
hspace="50" vspace="100">
</body>
</html>
Internet programming Compiled by:Tadesse K. 11/16/2016
2.13 HTML Images…
85
Fig Image
Internet programming insertion
Compiled by:Tadesse K. 11/16/2016
2.13 HTML Images…
86
Image Maps
Image maps enable you to define multiple links within a single image.
For example, if you have a picture of African countries, you can create
links in the image that opens each country’s picture/page for detailed
information.
Clickable regions within image maps can be basic shapes like rectangles
and circles or complex polygonalCompiled
Internet programming shapes.by:Tadesse K. 11/16/2016
Image Map…
87
The image is added to the web page in the usual way, but
with the addition of a usemap attribute, whose value must
be preceded by a hash sign (#).
Example:
To create the map used by img tag, we use the following tags
and attributes:
<map> tag maps information for an imagemap
name="text" - The legacy method for giving the map a name
id="text" - The current method for giving the map a name
<area> tag contains information for a clickable area in an
imagemap.
The <area> element specifies the shape and the coordinates
that define the boundaries of each clickable hotspot.
shape="rect|circle|poly" - shape of the linked area
coords="numbers" - pixel coordinates for the linked area
href="url"Internet
- target file forCompiled
programming the linkby:Tadesse K. 11/16/2016
Image Map…
90
Suppose you want to create clickable image map of regional states like the
following:
Each row is divided into data cells with the <td> tag.
cell.
A <td> tag can contain text, links, images, lists, forms, other
tables, etc.
Table headers
Headers in a table are defined with the <th> tag.
Header 1 Header 2
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2
Attributes of table:
• The attributes of a table will be applied on the whole table
element which include one or more rows (<tr>), header
cells (<th>) or data cells (<td>).
Example:
<table border="5" bordercolor="green" bgcolor="gray">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr><td rowspan="2">Row 1 Cell 1</td>
<td bgcolor="red">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>
which you will use to adjust the white space in your table cell.
Cellspacing defines the width of the border, while cellpadding
represents the distance between cell borders and the content
Internet programming Compiled by:Tadesse K. 11/16/2016
within.
2.14 Tables…
100
Example:
<table border="1" cellpadding="15" cellspacing="10">
<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>
You can use the valign attribute to set where the text is
displayed vertically.
The attribute can be added to a row or cell start tag, and set
to the desired value.
The head and foot are rather similar to headers and footers in a word-
processed document that remain the same for every page, while the body is
the main content of the table.
The three elements for separating the head, body, and foot of a table are:
<thead> - to create a separate table header.
<tbody> - to indicate the main body of the table.
<tfoot> - to create a separate table footer.
The most common HTML lists are ordered and unordered lists.
Unordered HTML List Ordered HTML List HTML Description List
Unordered List
An unordered list starts with the <ul> tag.
The list items are marked with bullets (typically small black circles).
The “type” attribute can be used to specifies the style of the bullet
points of the list items, its value includes disc, square and circle.
Example:
<ul>
<li>Banana</li>
<li>Orange</li>
</ul>
How the HTML code above looks in a browser:
• Banana
• Orange
Internet programming Compiled by:Tadesse K. 11/16/2016
Ordered and Unordered List…
110
Disc Circle:
<ul style="list-style-type:disc"> <li>Coffee</li> <ul style="list-style-type:circle"> <li>Coffee</li>
<li>Tea <li>Tea
<li>Milk</li> <li>Milk</li>
</ul> </ul>
Square: None:
<ul style="list-style-type:square"> <ul style="list-style-type:none">
<li>Coffee</li> <li>Coffee</li>
<li>Tea <li>Tea
<li>Milk</li> <li>Milk</li>
</ul> Internet programming </ul>
Compiled by:Tadesse K. 11/16/2016
Ordered and Unordered List…
111
Ordered List
An ordered list starts with the <ol> tag.
Example:
<ol start="17">
<li>Highlight the text with the text tool.</li>
<li>Select the Character tab.</li>
<li>Choose a typeface from the pop-up menu.</li>
</ol>
The resulting list items would be numbered 17, 18, and 19,
consecutively.
Internet programming Compiled by:Tadesse K. 11/16/2016
Ordered and Unordered List…
113
Type Description
type="I" The list items will be numbered with uppercase roman numbers
type="i" The list items will be numbered with lowercase roman numbers
Nesting Lists
One list can be put inside another to create nested list.
Example:
<ol>
<li>Super computer</li>
<li>Mainframe computer</li>
<li>Mini computer</li>
<li>Micro computer</li>
<ul>
<li>Desktop computer</li>
<li>Laptop Computer</li>
<li>Palmtop computer</li>
</ul>
</ol> Internet programming Compiled by:Tadesse K. 11/16/2016
2.16 Frames
116
<frameset cols="25%,75%">
<frame src="frame_a.htm" />
<frame src="frame_b.htm" />
</frameset>
The frameset column size can also be set in pixels
(cols="200,500"), and one of the columns can be set to use the
remaining space, with an asterisk (cols="25%,*").
You cannot use the body element together with the frameset
element.
However, if you add a <noframes> tag containing some text
for browsers that do not support frames, you will have to
enclose the text in a body element.
Internet programming Compiled by:Tadesse K. 11/16/2016
Frames…
119
Attributes of frameset
Example:
<frameset cols="30%,*">
<frame src="frame-one.html">
<frame src="frame-two.html">
</frameset>
Attributes of frame
Attribute Value Description
frameborder 0 or 1 Specifies whether or not to display a border around a frame
marginheight pixels Specifies the top and bottom margins of a frame
marginwidth pixels Specifies the left and right margins of a frame
noresize noresize Specifies that a frame cannot be resized
scrolling yes Specifies whether or not to display scrollbars in a frame
no
auto
src URL Specifies the URL of the document to show in a frame
Nested Frames
Framesets may be nested to any level. 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.
Example:
Text Field
You can create text field by using:
<input type="text">
This defines a one-line input field that a user can enter text into.
Example:
<input type="text" name="username" size="8" maxlength="8">
Password
A password field works just like a text entry field, except the
characters are obscured from view using asterisk (*) or bullet
(•) characters, or another character determined by the
browser.
We can define a password field like:
<input type="password" />
Example:
<form>
Password: <input type="password" name="pwd">
</form>
How the HTML code above looks in a browser:
Password:
Internet programming Compiled by:Tadesse K. 11/16/2016
2.17 HTML Forms and Input…
132
Text Area
At times, you may want your users to be able enter multiple
line of text.
For these instances, use the <textarea> element that is
Scrollbars will be provided if the user types more text than fits in the
allotted space.
cols - specifies the width of the text area measured in number of
characters.
Example:
Radio Buttons
Radio buttons are a popular form of interaction.
value: sets the value of the radio button. This is the data sent to
Checkboxes
Check boxes allow for multiple items to be selected for a certain
group of choices.
The check box's name and value attributes behave the same as a
radio button.
We can define a checkbox like:
<input type="checkbox">
Checkboxes let a user select ONE or MORE options.
Example:
<form>
<input type="checkbox" name="vehicle" value="Bike"> I have a
bike <br>
<input type="checkbox" name="vehicle" value="Car"> I have a
car
</form> Internet programming Compiled by:Tadesse K. 11/16/2016
2.17 HTML Forms and Input…
138
Selection lists
Drop down menus are created with the <select> and <option> tags.
value: sets the value of the checkbox. This is the data sent to server when
the user submits the form.
checked: sets whether the checkbox is checked by default or not. It accepts
the value checked.
Example:
Attributes of select
Attribute of option
Attribute value Description
selected selected Specifies whether the option is selected or not
when the form loads
Scrolling Lists
To make the menu display as a scrolling list, simply specify the number of
lines you’d like to be visible using the size attribute.
Example:
Select the fruits you like:
<select name="fruits" size="6" multiple="multiple">
<option>Orange</option>
<option>Apple</option>
<option selected="selected">Banana</option>
<option selected="selected">Mango</option>
<option> Avocado</option>
<option>Pineapple</option>
<option>Papaya</option>
<option>Strawberry</option>
Internet programming Compiled by:Tadesse K. 11/16/2016
</select>
2.17 HTML Forms and Input…
142
Button
There are a number of different kinds of buttons that can
be added to web forms.
Some are:
submit button,
reset button, and
client side button.
Submit Button
When clicked, the submit button immediately sends the
collected data in the form to the server for processing.
Submit button is defined as follows:
<input type="submit">
Internet programming Compiled by:Tadesse K. 11/16/2016
2.17 HTML Forms and Input…
144
Example:
<input type="button">
Internet programming Compiled by:Tadesse K. 11/16/2016
2.17 HTML Forms and Input…
146
Example:
Example:
Hidden controls
There may be times when you need to send information to the form
processing application that does not come from the user.
In these instances, you can use a hidden form control that sends data
when the form is submitted, but is not visible when the form is
displayed in a browser.
<input type="hidden">
Hidden controls are added using the input element with the type set
to hidden.
Its sole purpose is to pass a name/value pair to the server when the
form is submitted.
Example:
<input type="file">
Internet programming Compiled by:Tadesse K. 11/16/2016
2.17 HTML Forms and Input…
151
The browser displays a “file” input as a text field with a button that
allows the user to navigate the hard drive and select the file for
upload.
Example:
Example:
<embed src="example.mpeg" autostart="false" />
Example:
<embed src="http://www.computerhope.com/issues/ibm-linux.mov"
Pluginspage="http://www.apple.com/quicktime/" width="320" height="250"
CONTROLLER="true" LOOP="false" AUTOPLAY="false" name="IBM Video">
</embed>
File types that are supported by the embed tag are Flash movies (.swf),
mpeg(.mpg or .mpeg), AVI's (.avi), and MOV's (.mov).
.swf files - are the file types created by Adobe Flash program.
.wmv files - are Microsoft's Window's Media Video file types.
.mov files - are Apple's Quick Time Movie format.
.mpeg files - are movie files created by the Moving Pictures Expert Group.
Macromedia's .swf and .mpeg formats may be the best options for web
because the high compression reduces file size and expedites the download
periods for your page visitors.
Internet programming Compiled by:Tadesse K. 11/16/2016
2.19 HTML Special Characters
160
(Entities and Symbols)
Characters within HTML documents that are not part of a tag
are rendered as-is by the browser.
However, some characters have special meaning and are not
directly rendered, while other characters can't be typed into
the source document from a conventional keyboard.
Special characters need either a special name or a numeric
character encoding for inclusion in an HTML document.