Chapter 2 HTML
Chapter 2 HTML
HTML TAGS
1.Basic HTML Tags
1.1 HTML: Hypertext Markup Language
HTML stands for Hypertext Markup Language.
with </html>.
1.Basic HTML Tags…
Let us first see how a plain html code
looks like.
<html>
<head>
<title>Page title here </title>
</head>
<body>
Our body content here
</body>
</html>
1.Basic HTML Tags…
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.
1.Basic HTML Tags…
1.Basic HTML Tags…
<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.
</html>
1.Basic HTML Tags…
ISO 639-1 defines abbreviations for languages.
In HTML, they can be used in the lang attributes.
Language ISO Code
Chinese zh
English en
French fr
German de
Russian ru
Local language
Afar aa
Amharic am
Afan Oromo om
Somali so
Tigrinya ti
1.Basic HTML Tags…
<html lang=“om">
<head>
<title>Setting Language</title>
</head>
<body>
This web page in Afan Oromo
</body>
</html>
1.Basic HTML Tags…
<body> Attributes
Background Color
You can change background color of your web
page by using <BODY> tag attribute bgcolor
<body bgcolor=”green”>
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.
vlink: Sets a color for visited links - that is, for linked text
<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>
1.Basic HTML Tags…
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.
description
generator
keywords
content text Gives the value associated with the http-equiv
or name attribute
1.Basic HTML Tags…
The keywords attribute
Keywords meta tag defines keywords for search
engines.
It was a critical element for early search engines
(the link text) and the URL (the destination site, page or resource).
The URL is specified using href attribute.
Here is an example:
page
_top or _parent then same window will be used to display the
loaded document.
_self then loads the new page in current window. By default its
_self.
1.Basic HTML Tags…
Example: a link that opens on a new window
<a href="first.html" target="_blank"> First Page</a><br>
If you place the cursor over the link, you will see the text in the
title attribute.
Example:
<a href="http://www.html.net/" title="Visit html.net and learn
HTML">Learn HTML </a>
the link.
For example, you could make the T key an access key so that when
the user presses either the Alt or Ctrl key on his keyboard along
with the T key, the link gets activated.
Example:
document.
To link to an email, you type mailto: followed by an e-
mail address.
Example:
<a href="mailto:[email protected]">Send an e-mail to us
</a>
HTML Headings
In HTML, you can create different heading levels in your
document to help you organize the document into
sections, just as you might do when writing a book.
A heading element briefly describes the topic of the
section it introduces.
Headings are defined with the <h1> to <h6> tags.
<h1> defines the largest heading and <h6> the
smallest heading.
2. HTML Text Formatting
Tags…
Heading tags are block tags, and you must
specify opening and closing tags.
Example:
<body>
<h1>this is heading level 1.</h1>
<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>
2. HTML Text Formatting
Tags…
2.HTML Text Formatting
Tags…
HTML Paragraphs
Authors traditionally divide their thoughts and arguments
into sequences of paragraphs.
Along with using headings to structure your Web page, you
can add structure by grouping common text into
paragraphs.
headers, etc.
Example:
<p align="center">This is center aligned.</p>
<p align="justify">This is jutified. This works when you
have multiple lines in your paragraph and you want to
justify all the lines so that they can look more nice.</p>
2.HTML Text Formatting
Tags…
HTML Fonts
The <font> tag is used to add font type, size,
7(largest).
The default size of a font is 3.
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>
2.HTML Text Formatting
Tags…
2.HTML Text Formatting
Tags…
Specify Relative Font Size
You can also specify relative font sizes instead of exact font
size.
This can be done like:
<font size="+n">
<font size="-n">
This specifies how many sizes larger or how many sizes
Example:
<font size="-1">Font size="-1"</font>
<font size="+1">Font size="+1"</font>
<font size="+2">Font size="+2"</font>
<font size="+3">Font size="+3"</font>
2.HTML Text Formatting
Tags…
2.HTML Text Formatting
Tags…
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
Example:
<font face="Times New Roman" size="5"> Times New Roman
</font>
<font face="Verdana" size="5"> Verdana </font>
<font face="Comic sans MS" size="5"> Comic Sans MS </font>
<font face="WildWest" size="5"> WildWest </font>
2.HTML Text Formatting
Tags…
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 by listing the font face names,
separated by a comma.
Example:
<font face="arial, helvetica">
<font face="Lucida Calligraphy, Comic Sans MS,
Lucida Console>
2.HTML Text Formatting
Tags…
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:
<font color="#0000FF">This text blue color</font>
<font color="red">This text is red</font>
2.HTML Text Formatting
Tags…
The <basefont> Element:
The <basefont> element is used to set a default
font size, color, and typeface for any parts of the
document that are not otherwise contained within
a <font> element.
You can then use the <font> elements to override
the <basefont> settings.
in italicized face.
Example:
<p>The following word uses a <i>italicized</i>
typeface.</p>
This will produce following result:
2.HTML Text Formatting
Tags…
Underlined Text - The <u> Element:
Anything that appears in a <u>...</u> element
Example:
<p>The following word uses a
<u>underlined</u> typeface.</p>
This will produce following result:
The following word uses a underlined typeface.
2.HTML Text Formatting
Tags…
Centering Content - The <center> Element:
You can use <center> tag to put any content in
Example:
<p>This is not in the center.</p>
<center> <p>This is in the center.</p>
</center>
2.HTML Text Formatting
Tags…
Strike Text - The <strike> Element:
Anything that appears in a <strike>...</strike>
Example
<p>The following word uses a
<strike>strikethrough</strike> typeface.</p>
You can also use <br /> which does the same.
Example:
<pre>
function testFunction( int a, int b ){
int sum = a + b;
alert (sum);
return;
}
2.HTML Text Formatting
Tags…
This produces the following output:
function testFunction( int a, int b ){
int sum = a + b;
alert (sum);
return;
}
2. HTML Text Formatting
Tags…
Horizontal Rules - The <hr> Element
<hr> stands horizontal rules are used to visually break up
sections of a document.
The <hr> tag creates a horizontal line in an HTML page.
page.
Example:
<p> The chemical formula for water is H<sub>2</sub>O
</p>
<p> Solve 5X<sup>2</sup>+6X+10 </p>
2. HTML Text Formatting
Tags…
Big and small Text:
The <big> tag displays texts in big.
Example:
<bdo dir="rtl">Here is some Hebrew text!</bdo>
Example:
<img src="coffee.gif" alt="Highland coffee"
width="100" height="100" border="2" align="right"
title="HTML Tutorial" />
Inserting Image…
Inserting Image…
The valign attribute
The valign attribute sets vertical alignment of the
image and takes value either top, bottom or center.
Example:
<img src="image-map-image.gif" alt=“image map“
width="398"
height="398" usemap="#shapes" />
<area shape="poly" coords="56,71,52,75,51,84,50,95,48,97,43,94,36,99,35,107,
36,111,32,119,31, 128, 31,133,38,133,40,125,38,121,42,123,46, 124,48,116,50,112,
53,115,59,116,60,120,65,123,69,126,75,132,78,134,79,129,86,128,81,124,77,122,77,1
14,83,110,87,106,81,101,81,94,86,84,83,78,81,73,77,75,74,69,69,68,63,74,59,74,56,7
2" href="Benishangul.html" />
<area shape="poly" coords="32,146,37,147, 44,153,48,155,54,155,50,158,49,166, 53,170,58,172,59,
177,58,180,52,179,51,177,50,180,46,180,43,183,39,180,35,181,30,176,27,170,20,166,13,166,5,164,6,1
59,9,156,10,150,21,149,23,151,32,148,32,146" href="Gambella.html" />
Table headers
Headers in a table are defined with the <th> tag.
The text in a <th> element will be bold and
centered.
3. Tables…
If you do not specify a border attribute, the table will be
displayed without borders.
Sometimes this can be useful, but most of the time, we
want the borders to show.
Example:
<table border="1">
<tr>
<th>Header 1</th> <th>Header 2</th>
</tr>
<tr>
<td>row 1, cell 1</td> <td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td> <td>row 2, cell 2</td>
</tr>
3. Tables…
HTML code above looks in a browser:
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>).
Attribute Value Description
align Left Specifies the alignment of a table according to
Center surrounding text
right
cellpadding pixels Specifies the space between the cell wall and the
cell content
cellspacing pixels Specifies the space between cells
width Pixels Specifies the width of a table
%
height Pixels Specifies the height of a table
%
3. Tables…
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>
3. Tables…
nowrap nowrap Specifies that the content inside a cell should not wrap
valign top|middle|bottom Vertical aligns the content in a table row
3. Tables…
Spanning rows and cells
<table border="1" cellpadding="2">
<tr>
<td>A cell</td>
<td>Another cell</td>
<td>Yet another cell!</td>
</tr>
<tr>
<td rowspan="2">A cell that spans two rows</td>
<td colspan="2">A cell that spans two columns</td>
</tr>
<tr>
<td>Another cell</td>
<td>The last cell</td>
</tr>
3. Tables…
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.
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>
<ul> attributes:
Ordered List
An ordered list starts with the <ol> tag.
Example:
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.
Ordered and Unordered List…
Example:
Types of fruits are:
<ol type=”I”>
<li>Banana</li>
<li>Orange</li>
<li>Apple</li>
</ol>
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>
Frames
Frames can divide the screen into separate
windows.
Each of these windows can contain an HTML
document.
A file that specifies how the screen is divided into
frames is called a frameset.
The frameset page lacks a <body> element
(although it still requires head and title elements)
and instead uses a <frameset> element, which sets
the attributes for how the frames are positioned.
The frameset element houses frame elements,
which define the location and attribute of each
frame.
Frames…
When a frameset page is loaded, the browser
automatically loads each of the pages associated with the
frames.
Each HTML document is called a frame, and each frame is
independent of the others.
The disadvantages of using frames are:
The web developer must keep track of more HTML documents
It is difficult to print the entire page
Example:
<FRAMESET cols="33%, 33%, 34%">
<frame src=”one.html”>
<FRAMESET rows="40%, 50%">
<frame src=”two.html”>
<frame src=”three.html”>
</FRAMESET>
<frame src=”four.html”>
Frames…
Working with iframes (internal frames)
The <iframe> tag defines an inline frame that
<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"
HTML Forms…
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:
HTML Forms…
Text Area
At times, you may want your users to be able
Example:
<textarea name="comment"> Tell us what you
feel about our tutorial with 50 words or less.
</textarea>
HTML Forms…
Text Area attributes:
Text area has the following attributes:
display.
Scrollbars will be provided if the user types more text than fits
of characters.
Example:
<textarea name="comment" rows="5" cols="100"> Tell us
what you feel about our tutorial with 50 words or less.
</textarea>
HTML Forms…
Radio Buttons
Radio buttons are a popular form of interaction.
Example
<form>
<input type="radio" name="sex" value="male">
Male<br>
<input type="radio" name="sex" value="female">
Female
</form>
HTML Forms…
Radio button attributes are:
name: sets name of the radio button
Example:
<form method=”post” action=”register.php”>
<input type="radio" name="sex" value="male"
checked=”checked”> Male <br>
HTML Forms…
Checkboxes
Check boxes allow for multiple items to be selected for a
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 bike <br>
<input type="checkbox" name="vehicle" value="Car"> I
have car
</form>
HTML Forms…
Selection lists
Drop down menus are created with the <select> and <option>
tags.
<select> is the list itself and each <option> is an available
Example:
Educational level: <br>
<select name="degree">
<option>Choose One</option>
<option>Some High School</option>
<option>High School Degree</option>
<option>Some College</option>
<option>Bachelor's Degree</option>
<option>Doctorate</option>
</select>
HTML Forms…
Checkbox attributes are:
name: sets name of the checkbox
value: sets the value of the checkbox. This is the data sent to
Example:
What type of food do you like?
<ul>
<li><input type="checkbox" name="genre" value=" spaghetti "
checked="checked"> Spaghetti</li>
<li><input type="checkbox" name="genre" value="pizza"
checked="checked"> Pizza</li>
<li><input type="checkbox" name="genre" value="sandwich">Sandwich
</li>
<li><input type="checkbox" name="genre" value="Burger">Burger</li>
</ul>
HTML Forms…
Attributes of select
Attribute of option
Attribute value Description
selected selected Specifies whether the option is selected or not
when the form loads
HTML Forms…
Scrolling Lists
To make the menu display as a scrolling list, simply specify the
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>
HTML Forms…
This produces the following output:
HTML Forms…
Button
There are a number of different kinds of buttons that
submit button,
reset button, and
client side button.
Submit Button
When clicked, the submit button immediately sends the
label.
name: used to give name to the submit button
Example:
<input type=”submit” name=”info” value=”Send”>
Reset Button
The reset button returns the form controls to the state
JavaScript.
It has no predefined function on its own, as submit
Example:
<input type=”button” name=”adder” value=”Add”>
Image Button
This type of input control allows you to replace the
button
value: text displayed on the button
Example:
<input type="image" src="didessa.png"
value="Submit">
HTML Forms…
The button element
The button element is a flexible element for creating
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="hidden" name="page"
value="http://www.example.com/littlechair_thankyou.html">
HTML Forms…
File selection control
Web forms can collect more than just data.
Example:
<input type="file">
HTML Forms…
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:
<input type="file" name="photo" size="28" id="form-photo">
Example:
<form action="client.php" method="post"
enctype="multipart/form-data">
<p> Send a photo to be used as your online icon:<br>
<input type="file" name="photo" size="28" id="form-photo"
/></p>
<html>
<head> <title>Form Elements</title> </head>
<body>
<form name="test" method="post">
First name: <input type="text" name="fname"> <br>
Last name: <input type="text" name="lname"> <br>
Sex: <input type="radio" name="sex" value="male" checked> Male
<input type="radio" name="sex" value="female"> Female
<br>
Educational level: <br>
<select name="education" size="6">
<option>Primary School</option> <option>Secondary School</option>
<option>College Diploma</option> <option>First Degree</option>
<option>Masters Degree</option> <option>PhD</option>
</select> <br>
Which fields are you interested in? <br>
<input type="checkbox" name=“choice1" value="Electronics"> Electronics <br>
<input type="checkbox" name=“choice2" value="Software Engineering"> Software
Engineering <br>
<input type="checkbox" name=“choice3" value="Computer Engineering"> Computer
Engineering <br>
<input type="checkbox" name=“choice4" value="Networking"> Networking
<br> <br>
Tell us what you feel about our tutorial with 50 words or less. <br>
<textarea name="comment" rows="10" cols="50"> </textarea> <br>
<input type="submit" name="submit">
</form>
</body>
HTML Forms…
Linking HTML Forms with PHP Scripts
To create a link between PHP scripts and HTML
Buttons:
Submit buttons: When activated, a submit
button.
HTML Forms…
A submit button is used to send form data to a
server.
The data is sent to the page specified in the
form's action attribute .
The file defined in the action attribute usually
does something with the received input:
Example:
<embed src="example.mpeg" autostart="false" />
Inserting Multimedia…
The following is the list of important attributes for <embed> element.
align - determines how to align the object. It takes either center, left or right.
autostart - Indicates if the media should start playing automatically. Netscape
default is true, Internet Explorer is false.
loop - Specifies if the sound should be played continuously (set loop to true), a
certain number of times (a positive value) or not at all (false). This is supported
by Netscape only.
playcount - Specifies the number of times to play the sound. This is alternate
option for loop if you are usiong IE.
hidden - Defines if the object shows on the page. A false value means no and
true means yes.
height – set height of the object.
width – set width of the object.
pluginspage - Specifies the URL to get the plugin software.
name - A name used to reference the object.
src - URL of the object to be embedded. This can be any recognizable by the
user's browser. It could be .mid, .wav, .mp3, .avi and so on).
volume - Controls volume of the sound. Can be from 0 (off) to 100 (full
volume). This attribute is supported by Netscape only.
Controller – whether to show controllers like play, stop, pause, etc.
Inserting Multimedia…
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.