Chapter 1 - HTML
Chapter 1 - HTML
HTML
1.HTML: Hypertext Markup Language
Our web page should start with <html> and end with </html>
The total code is divided into two parts and both the parts are
kept inside <html> tag
The first part inside this html tags is the head and it starts with
<head> and ends with </head>.
????What we put in the head will not be displayed to users.
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.2 HTML, HEAD and BODY Tags…
1.2 HTML, HEAD and BODY 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.
Title tags are used to give title to the browser window.
Title tags are also important for our search engine point of view.
Search engine is an application that searches for and retrieve internet to
access contents of documents in it
We should keep most important keywords inside the title tag.
1.2 HTML, HEAD and BODY Tags…
Example:
<html>
<head>
<title> Nuclear Energy </title>
</head>
<body>
Nuclear energy is one of the clean environment friendly
energy source.
</body>
</html>
1.2 HTML, HEAD and BODY Tags…
<title> element.
This element is a child of the <head> element.
<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.
1.2 HTML, HEAD and BODY Tags…
B. 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">
C. 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. A link that the user has already clicked on is
Example:
<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>
<a href="first2.html">third page</a><br>
<a href="first3.html">last page</a><br>
</body>
</html>
1.3 Creating Links
A hyperlink or link is a word, group of words, or image that
you can click on to jump to a new document or a new section
within the current document.
Web pages can contain links that take you directly to other
pages or specific parts of the given page.
These links are known as hyperlinks.
attribute
To create a bookmark inside a document, by using the name
attribute
1.3 Creating Links…
The href Attribute:
A link in HTML is always composed of two parts, the clickable part (the link
Here is an example:
If set to:
– _blank then a new window will be opened to display the loaded 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.3 Creating Links…
Example: a link that opens on a new window/tab
<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:
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:
When the link is clicked, the default e-mail program opens with a
new blank message addressed to the specified e-mail address.
This function will only work if there is an e-mail program installed
on your computer.
2. HTML Text Formatting Tags
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.
Align attribute can be used also with other tags like 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, and color to the
– size,
– color, and
– face
They are used to customize your fonts.
To change any of the font attributes at any time within your
page, simply use the <font> tag.
The text that follows will remain changed until you close with
the </font> tag.
You can change any or all of font attributes at the one time.
2.HTML Text Formatting Tags…
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>
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.
<font size="+n">
<font size="-n">
This specifies how many sizes larger or how many sizes smaller than
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 the font
attribute.
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…
Formatting Tags
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.
face.
Example:
<p>The following word uses an <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 is displayed
with underline.
Example:
<p>The following word uses a <u>underlined</u>
typeface.</p>
This will produce following result:
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> element is
Example
<p>The following word uses a <strike>strikethrough</strike>
typeface.</p>
You can also use <br /> which does the same.
The <br /> element has a space between the characters br and the
forward slash.
If you omit this space, older browsers will have trouble rendering
the line break, while if you miss the forward slash character and just
use <br> it is not valid XHTML.
2.HTML Text Formatting Tags…
Example
Hello<br>
You come most carefully upon your hour.<br />
Thanks<br>
Mahnaz
HTML document.
In those cases, you can use the preformatted tag (<pre>).
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 ){
var sum = a + b;
alert (sum);
return;
}
2. HTML Text Formatting
Tags…
Horizontal Rules - the <hr> Element
<hr> horizontal rules are used to visually break up sections of a document.
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:
<p>This is paragraph one and should be on top</p>
2. HTML Text Formatting
Tags…
Subscript and Superscript Text:
The <sub> tag defines subscript text.
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.
HTML comment are indicated by beginning tag <!-- and ending tag
-->
You can comment multiple lines by the special beginning tag <!--
and ending tag --> placed before the first line and end of the last line
to be treated as a comment.
attribute.
The value of the src attribute is the URL of the image you
want to display.
3. Inserting Image…
Syntax for inserting an image:
<img src="url" alt="Alternative Text"/>
Example:
<img src="boat.gif" alt="Big Boat" />
3. Inserting Image…
The width and height attributes
To define the height and width of the image, rather than
letting the browser compute the size, use
the height and width attributes.
The attributes:
width: sets width of the image.
This can have a value like 10 or 20% etc.
height: sets height of the image.
This can have a value like 10 or 20% etc.
Example:
<img src=”sunset.jpg” height=”50” width=”100”>
3. Inserting Image…
The border attribute
The border attribute sets a border around the image.
This will have a value like 1 or 2 etc.
Example:
<img src="coffee.gif" alt="Highland coffee" width="100"
height="100" border="2" align="right" title=“Coffee
products" />
3. Inserting Image…
3. Inserting Image…
The valign attribute
The valign attribute sets vertical alignment of the image and takes
value either top, bottom or center.
Table headers
Headers in a table are defined with the <th> tag.
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>
</table>
3. Tables…
The head and foot remain the same for every page, while the body is
The three elements for separating the head, body, and foot are:
<thead> - to create a separate table header.
The list items are marked with bullets (typically small black circles).
The “type” attribute can be used to specifies the style of the bullets its value
Example:
<ul>
<li>Banana</li>
<li>Orange</li>
</ul>
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…
The <ol> attributes:
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>
Ordered and Unordered List…
Definition lists
Definition lists vary only slightly from other types of lists in that list
content.
The description is given with a <dd> element that contains block-
level content.
Definition (or dictionary) lists are used for lists of terms with their
respective definitions.
The whole list is marked up as a definition list (<dl>) element.
The content of a <dl> is some number of terms (indicated by the
<dt> element) and definitions (indicated by the <dd> element).
Here is an example of a brief definition list :
<dl>
<dt>Linotype</dt>
<dd>Line-casting allowed type to be selected, used, then recirculated into the
machine automatically. This advance increased the speed of typesetting and
printing dramatically.</dd>
<dt>Photocomposition</dt>
<dd>Typefaces are stored on film then projected onto photo-sensitive paper. Lenses
adjust the size of the type.</dd>
<dt>Digital type</dt>
<dd><p>Digital typefaces store the outline of the font shape in a format such as
Postscript. The outline may be scaled to any size for output.</p>
<p>Postscript emerged as a standard due to its support of graphics and its early
support on the Macintosh computer and Apple laser printer.</p>
</dd>
</dl>
Grouping Elements: the DIV and SPAN Elements
The DIV and SPAN elements offer a generic mechanism for adding
structure to documents.
The SPAN element defines the content to be inline and DIV to be
block-level but both impose no other presentational idioms on the
content.
Thus, authors may use these elements in conjunction with style sheets
to tailor HTML to their own needs and tastes.
Here is another common use of a div used to break a page into sections for
context, structure, and layout purposes.
In this example, a heading and several paragraphs are enclosed in a div
Example:
<P><SPAN class="client-title">Client information:</SPAN>
</P>
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)
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
Users can’t save frame properly
In the following example, the outer FRAMESET divides the available space into
height.
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 contains
another document.
<iframe>s enable you to update a page section without
The most important element inside form element is the input element.
The input element is used to accept user information.
An input element can vary in many ways, depending on the type
attribute.
An input element can be of type text field, checkbox, password, radio
button, submit button, and more.
The most used input types are described in the next subsections.
HTML Forms…
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:
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 enter multiple
line of text.
For these instances, use the <textarea> element that is
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:
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:
<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
value: sets the value of the radio button. This is the data
Example:
<form method=”post” action=”register.php”>
<input type="radio" name="sex" value="male"
checked=”checked”> Male <br>
<input type="radio" name="sex" value="female"> Female
</form>
HTML Forms…
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 bike
<br>
<input type="checkbox" name="vehicle" value="Car"> I have car
</form>
HTML Forms…
Checkbox attributes are:
name: sets name of the checkbox
value: sets the value of the checkbox. This is the data sent to server when
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>
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 choice for the
user.
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…
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 number of lines
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 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
Example:
<input type=”submit” name=”info” value=”Send”>
Reset Button
The reset button returns the form controls to the state they were in
selections made.
HTML Forms…
Reset button can be defined as follows:
<input type="reset">
buttons do.
Example:
<input type=”button” name=”adder” value=”Add”>
Image Button
This type of input control allows you to replace the submit
Example:
<input type="image" src="didessa.png" value="Submit">
HTML Forms…
The button element
The button element is a flexible element for creating custom buttons similar to
on the button.
Attribute:
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.
They can also be used to transmit external documents from a user’s hard
drive.
For example, a printing company could use a web form to receive artwork
photo contest.
The file selection control makes it possible for users to select a document
from the hard drive to be submitted with the form data.
It is added to the form using our old friend the input element with its type set
to file.
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>
</form>
<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 forms, we
need to use the submit button, and the attribute of the <form
tag>, specifically “action” and “method”.
Buttons:
Submit buttons: When activated, a submit button submits a
form.
A form may contain more than one 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.
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.