Ip ch2
Ip ch2
HTML TAGS
1.Basic HTML Tags
1.1 HTML: Hypertext Markup Language
HTML stands for Hypertext Markup Language.
</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.
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 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>
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.
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 robots meta tag lets you specify that a particular page
on the page.”
Your page will drop out of the search index and your links
This can be used by caches to determine when to fetch a fresh copy of the
associated document.
1.Basic HTML Tags…
The author attribute
The author attribute defines the author of the page. The
structure is:
<meta name="author" content="John Li">
1.Basic HTML Tags…
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
Here is an example:
_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>
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:
Example:
<a href="mailto:[email protected]">Send an e-mail to us </a>
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
There are options if one wants to create a text in HTML.
Let’s see some of the tags than can be used to create text
information.
HTML Headings
In HTML, you can create different heading levels in your
introduces.
Headings are defined with the <h1> to <h6> tags.
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
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
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
the preset font size should be.
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>
<font size="+4">Font size="+4"</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
installed, they will not be able to see it.
Instead they will default to Times New Roman of your font with size
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…
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.
displayed in bold.
The <b> tag makes text to be displayed in bold face.
2.HTML Text Formatting Tags…
Example:
<p>The use nuclear energy needs <b> safety caution </b>
because of the associated danger.</p>
This will produce following result:
The use nuclear energy needs safety caution because of the
associated danger.
Example:
<p>The following word uses a <i>italicized</i> typeface.</p>
This will produce following result:
The following word uses a italicized typeface.
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>
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
Example:
<pre>
function testFunction( int a, int b ){
int sum = a + b;
alert (sum);
return;
}
</pre>
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.
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> 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.
The <bdo> tag allows you to specify the text direction and
Example:
<bdo dir="rtl">Here is some Hebrew text!</bdo>
HTML Comment lines are indicated by the beginning tag <!-- and
ending tag --> placed at the beginning and end of every line to be
treated as a comment.
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.
Example:
<img src="boat.gif" alt="Big Boat" />
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”>
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="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" />
The value of the usemap attribute must correlate with the id values
of the associated map element.
The name attribute is required for backward compatibility, whereas
the id attribute is mandatory.
<map id="shapes" name="shapes">
</map>
Image Map…
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
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>
</table>
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
bgcolor rgb(x,x,x) Specifies the background color for a table
#xxxxxx
colorname
background Image url Sets background image of the table
border pixels Specifies the width of the borders around a table
bordercolor rgb(x,x,x) Specifies the color used for the border
#xxxxxx
colorname
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…
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 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>
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>
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”>
</FRAMESET>
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
<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">
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 sent to
server when the user submits the form.
checked: sets whether the radio button is checked by default or
not. It accepts the value checked.
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 a
bike <br>
<input type="checkbox" name="vehicle" value="Car"> I have a
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 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…
Checkbox attributes are:
name: sets name of the checkbox
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:
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 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>
</select>
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 data in the form to the server for processing.
Reset Button
The reset button returns the form controls to the state they
were in when the form loaded.
This clears the text users typed into text fields, and removes
selections made.
HTML Forms…
Reset button can be defined as follows:
<input type="reset">
Example:
<input type=”button” name=”adder” value=”Add”>
Image Button
This type of input control allows you to replace the submit
button with an image of your choice.
The image will appear flat, not like a 3-D button.
HTML Forms…
Image button can be defined as follows:
<input type="image">
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 those created with the input element.
The content of the button element (text and/or images) is what
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
for a business card order.
A magazine could use a form on their site to collect digital photos for a
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="" value="Electronics"> Electronics <br>
<input type="checkbox" name="" value="Software Engineering"> Software Engineering <br>
<input type="checkbox" name="" value="Computer Engineering"> Computer Engineering <br>
<input type="checkbox" name="" 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>
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.
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.