0% found this document useful (0 votes)
31 views29 pages

CH 2

Uploaded by

Legesse Samuel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views29 pages

CH 2

Uploaded by

Legesse Samuel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

UNIT TWO

HTML Basics
HTML is the building block for web pages. You will learn to use HTML to author an
HTML page to display in a web browser.
Objectives:
By the end of this course, you will be able to:

 Use a text editor to author an HTML document.


 Be able to use basic tags to denote paragraphs, emphasis or special type.
 Create hyperlinks to other documents.
 Create an email link.
 Add images to your document.
 Use a table for layout.
 Apply colors to your HTML document.

What is html File?


HTML is a format that tells a computer how to display a web page. The documents
themselves are plain text files with special "tags" or codes that a web browser uses to
interpret and display information on your computer screen.

 HTML stands for Hyper Text Markup Language


 An HTML file is a text file containing small markup tags
 The markup tags tell the Web browser how to display the page
 An HTML file must have an htm or html file extension

Try It?
Open your text editor and type the following text:
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<b> This is my first homepage. </b>
</body>
</html>
Save the file as mypage.html. Start your Internet browser. Select Open (or Open Page) in the
File menu of your browser. A dialog box will appear. Select Browse (or Choose File) and
locate the html file you just created - mypage.html - select it and click Open. Now you
should see an address in the dialog box, for example C:\MyDocuments\mypage.html. Click
OK, and the browser will display the page. To view how the page should look, visit this web
page: http://profdevtrain.austincc.edu/html/mypage.html

The text between the <head> tag and the </head> tag is header information. Header
information is not displayed in the browser window. The text between the <title> tags
is the title of your document. The <title> tag is used to uniquely identify each document
and is also displayed in the title bar of the browser window. The text between the <body>
tags is the text that will be displayed in your browser. The text between the <b> and </b>
tags will be displayed in a bold font.

1|Page Internet and Web Development


HTM or HTML Extension?
When you save an HTML file, you can use either the .htm or the .html extension. The .htm
extension comes from the past when some of the commonly used software only allowed
three letter extensions.
It is perfectly safe to use either .html or .htm, but be consistent. Mypage.htm and
mypage.html are treated as different files by the browser.

How to View HTML Source


A good way to learn HTML is to look at how other people have coded their html pages. To
find out, simply click on the View option in your browsers toolbar and select Source or Page
Source. This will open a window that shows you the actual HTML of the page. Go ahead
and view the source html for this page.

HTML Tags
What are HTML tags?
 HTML tags are used to mark-up HTML elements
 HTML tags are surrounded by the two characters < and >
 The surrounding characters are called angle brackets
 HTML tags normally come in pairs like <b> and </b>
 The first tag in a pair is the start tag, the second tag is the end tag
 The text between the start and end tags is the element content
 HTML tags are not case sensitive, <b> means the same as <B>

Logical vs. Physical Tags


In HTML there are both logical tags and physical tags. Logical tags are designed to describe
(to the browser) the enclosed text's meaning. An example of a logical tag is the <strong>
</strong> tag. By placing text in between these tags you are telling the browser that the
text has some greater importance. By default all browsers make the text appear bold when in
between the <strong> and
</strong> tags.
Physical tags on the other hand provide specific instructions on how to display the text they
enclose. Examples of physical tags include:
<b>: Makes the text bold.
<big>: Makes the text usually one size bigger than what's around it.
<i>: Makes text italic.
Physical tags were invented to add style to HTML pages because style sheets were not
around, though the original intention of HTML was to not have physical tags. Rather than
use physical tags to style your HTML pages, you should use style sheets.

HTML Elements
Remember the HTML example from the previous page:
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
This is my first homepage. <b>This text is bold</b>
</body>
</html>
This is an HTML element:
<b>This text is bold</b>
2|Page Internet and Web Development
The HTML element begins with a start tag: <b> The content of the HTML element is: This
text is bold
The HTML element ends with an end tag: </b>
The purpose of the <b> tag is to define an HTML element that should be displayed as bold.
This is also an HTML element:
<body>
This is my first homepage. <b>This text is bold</b>
</body>
This HTML element starts with the start tag <body>, and ends with the end tag
</body>. The purpose of the <body> tag is to define the HTML element that contains
the body of the HTML document.

Nested Tags
You may have noticed in the example above, the <body> tag also contains other tags, like
the <b> tab. When you enclose an element in with multiple tags, the last tag opened should
be the first tag closed. For example:

<p><b><em>This is NOT the proper way to close nested tags.</p></em></b>


<p><b><em>This is the proper way to close nested tags. </em></b></p>

Note: It doesn't matter which tag is first, but they must be closed in the proper order.

Why Use Lowercase Tags?


You may notice we've used lowercase tags even though I said that HTML tags are not case
sensitive.
<B> means the same as <b>. The World Wide Web Consortium (W3C), the group
responsible for developing web standards, recommends lowercase tags in their HTML 4
recommendation, and XHTML (the next generation HTML) requires lowercase tags.

Tag Attributes
Tags can have attributes. Attributes can provide additional information about the HTML
elements on your page. The <tag> tells the browser to do something, while the attribute
tells the browser how to do it. For instance, if we add the bgcolor attribute, we can tell the
browser that the background color of your page should be blue, like this: <body
bgcolor="blue">.

This tag defines an HTML table: <table>. With an added border attribute, you can tell the
browser that the table should have no borders: <table border="0">. Attributes always
come in name/value pairs like this: name="value". Attributes are always added to the start
tag of an HTML element and the value is surrounded by quotes.

Quote Styles, "red" or 'red'?


Attribute values should always be enclosed in quotes. Double style quotes are the most
common, but single style quotes are also allowed. In some rare situations, like when the
attribute value itself contains quotes, it is necessary to use single quotes:

name='George "machine Gun" Kelly'


Note: Some tags we will discuss are deprecated, meaning the World Wide Web
Consortium (W3C) the governing body that sets HTML, XML, CSS, and other technical
standards decided those tags and attributes are marked for deletion in future versions of
3|Page Internet and Web Development
HTML and XHTML. Browsers should continue to support deprecated tags and attributes,
but eventually these tags are likely to become obsolete and so future support cannot be
guaranteed.

Basic HTML Tags


The most important tags in HTML are tags that define headings, paragraphs and line breaks.
Basic HTML Tags

Tag Description
<html> Defines an HTML document
<body> Defines the document's body
<h1> to <h6> Defines header 1 to header 6
<p> Defines a paragraph
<br> Inserts a single line break
<hr> Defines a horizontal rule
<!--> Defines a comment

Headings
Headings are defined with the <h1> to <h6> tags. <h1> defines the largest heading
while <h6> defines the smallest.
<h1>This is a heading</h1>
<h2>This is a heading</h2>

<h3>This is a heading</h3>

<h4>This is a heading</h4>

<h5>This is a heading</h5>

<h6> This is a heading</h6>

HTML automatically adds an extra blank line before and after a heading. A useful heading
attribute is align.

<h5 align="left">I can align headings </h5>


<h5 align="center">This is a centered heading </h5>
<h5 align="right">This is a heading aligned to the right
</h5>

Paragraphs
Paragraphs are defined with the <p> tag. Think of a paragraph as a block of text. You can
use the align attribute with a paragraph tag as well.

<p align="left">This is a paragraph</p>


<p align="center">this is another paragraph</p>
Important: You must indicate paragraphs with <p> elements. A browser ignores any
indentations or blank lines in the source text. Without <p> elements, the document

4|Page Internet and Web Development


becomes one large paragraph. HTML automatically adds an extra blank line before and after
a paragraph.
Line Breaks
The <br> tag is used when you want to start a new line, but don't want to start a new
paragraph. The
<br> tag forces a line break wherever you place it. It is similar to single spacing in a
document.

This Code Would Display


This
<p>This <br> is a para<br> graph is a para
with line breaks</p> graph with line breaks

The <br> tag has no closing tag.


Horizontal Rule
The <hr> element is used for horizontal rules that act as dividers between sections, like
this:

The horizontal rule does not have a closing tag. It takes attributes such as align and width.
For instance:

This Code Would Display


<hr width="50%" align="center">

Comments in HTML
The comment tag is used to insert a comment in the HTML source code. A comment can be
placed anywhere in the document and the browser will ignore everything inside the
brackets. You can use comments to write notes to yourself, or write a helpful message to
someone looking at your source code.

This Code Would Display


<p> This html comment would <!--
This is a comment --> be This HTML comment would be displayed like
displayed like this.</p> this.

Notice you don't see the text between the tags <!-- and -->. If you look at the source
code, you would see the comment. To view the source code for this page, in your browser
window, select View and then select Source.
Note: You need an exclamation point after the opening bracket <!-- but not before the
closing bracket -->.
HTML automatically adds an extra blank line before and after some elements, like before
and after a paragraph, and before and after a heading. If you want to insert blank lines into
your document, use the <br> tag.
Try It Out!
Open your text editor and type the following text:

<html>
<head>
<title>My First Webpage</title>

5|Page Internet and Web Development


</head>
<body>
<h1 align="center">My First Webpage</h1>
<p>Welcome to my first web page. I am writing this page using
a text editor and plain old html.</p>
<p>By learning html, I'll be able to create web pages like a
pro....<br>
which I am of course.</p>
</body>
</html>

Save the page as mypage2.html. Open the file in your Internet browser. To view how the
page should look, visit this web page: http://profdevtrain.austincc.edu/html/mypage2.html

Other HTML Tags


As mentioned before, there are logical styles that describe what the text should be and
physical styles which actually provide physical formatting. It is recommended to use the
logical tags and use style sheets to style the text in those tags.

Logical Tags Physical Tags


Tag Description
Tag Description <b> Defines bold text
<abbr> Defines an abbreviation
<big> Defines big text
<acronym> Defines an acronym
<i> Defines italic text
<address> Defines an address element
<small> Defines small text
<cite> Defines a citation
<sup> Defines superscripted text
<code> Defines computer code text <sub> Defines subscripted text
<blockquote> Defines a long quotation <tt> Defines teletype text
<del> Defines text <u> Deprecated. Use styles instead
<dfn> Defines a definition term
<em> Defines emphasized text
<ins> Defines inserted text
<kbd> Defines keyboard text
<pre> Defines preformatted text
<q> Defines a short quotation
<samp> Defines sample computer code
<strong> Defines strong text
<var> Defines a variable

Character tags like <strong> and <em> produce the same physical display as <b> and
<i> but are more uniformly supported across different browsers.
Some Examples:
The following paragraph uses the <blockquote> tag. In the previous sentence, the
blockquote tag is enclosed in the <samp> Sample tag.
We the people of the United States, in order to form a more perfect Union, establish Justice,
insure domestic Tranquility, provide for the common defense, promote the general Welfare,
6|Page Internet and Web Development
and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish
this Constitution for the United States of America.

Although most browsers render blockquoted text by indenting it, that's not specifically what
it's designed to do. It's conceivable that some future browser may render blockquoted text in
some other way. However, for the time being, it is perfectly safe to indent blocks of text
with the <blockquote>.

This Code Would Display


<abbr title="World Wide Web">WWW</abbr> WWW
When you hold your mouse pointer over the WWW, text in the title attribute will appear in.

HTML Character Entities


Some characters have a special meaning in HTML, like the less than sign (<) that defines
the start of an HTML tag. If we want the browser to actually display these characters we
must insert character entities in place of the actual characters themselves.
The Most Common Character Entities:

Result Description Entity Name Entity Number


non-breaking space &nbsp; &#160;
< less than &lt; &#60;
> greater than &gt; &#62;
& Ampersand &amp; &#38;
" quotation mark &quot; &#34;
' Apostrophe &apos; (does not work in IE) &#39;

A character entity has three parts: an ampersand (&), an entity name or an entity number,
and finally a semicolon (;). The & means we are beginning a special character, the ; means
ending a special character and the letters in between are sort of an abbreviation for what it's
for. To display a less than sign in an HTML document we must write: &lt; or &#60; The
advantage of using a name instead of a number is that a name is easier to remember. The
disadvantage is that not all browsers support the newest entity names, while the support for
entity numbers is very good in almost all browsers.
Note: Entities are case sensitive.

Non-breaking Space
The most common character entity in HTML is the non-breaking space &nbsp;. Normally
HTML will truncate spaces in your text. If you add 10 spaces in your text, HTML will
remove 9 of them. To add spaces to your text, use the &nbsp; character entity.
7|Page Internet and Web Development
This Code Would Display
<p> This code would
appear as this.</p> This code would appear as this.

This Code Would Display


<p> This code &nbsp;&nbsp;&nbsp; This code would appear with three extra
would appear with three extra spaces.
spaces.</p>
To see a list of character entities, visit this page:

HTML Fonts

The <font> tag in HTML is deprecated. The World Wide Web Consortium (W3C) has
removed the
<font> tag from its recommendations. In future versions of HTML, style sheets (CSS)
will be used to define the layout and display properties of HTML elements.
The <font> Tag Should NOT be used.

HTML Backgrounds
Backgrounds
The <body> tag has two attributes where you can specify backgrounds. The background
can be a color or an image.

Bgcolor
The bgcolor attribute specifies a background-color for an HTML page. The value of this
attribute can be a hexadecimal number, an RGB value, or a color name:

<body bgcolor="#000000">
<body bgcolor="rgb(0,0,0)">
<body bgcolor="black">

The lines above all set the background-color to black.

Background
The background attribute can also specify a background-image for an HTML page. The
value of this attribute is the URL of the image you want to use. If the image is smaller than
the browser window, the image will repeat itself until it fills the entire browser window.

<body background="clouds.gif">
<body
background="http://profdevtrain.austincc.edu/html/graphics/cl
ouds.gif">

The URL can be relative (as in the first line above) or absolute (as in the second line above).
If you want to use a background image, you should keep in mind:

 Will the background image increase the loading time too much?
 Will the background image look good with other images on the page?
 Will the background image look good with the text colors on the page?
 Will the background image look good when it is repeated on the page?
 Will the background image take away the focus from the text?
8|Page Internet and Web Development
Note: The bgcolor, background, and the text attributes in the <body> tag are deprecated in
the latest versions of HTML (HTML 4 and XHTML). The World Wide Web Consortium
(W3C) has removed these attributes from its recommendations. Style sheets (CSS) should
be used instead (to define the layout and display properties of HTML elements).

Try It Out!
Open your text editor and type the following text:
<html>
<head>
<title>My First Webpage</title>
</head>
<body
background="http://profdevtrain.austincc.edu/html/graphics/cl
ouds.gif" bgcolor="#EDDD9E">
<h1 align="center">My First Webpage</h1>
<p>Welcome to my <strong>first</strong> webpage. I am writing
this page using a text editor and plain old html.</p>
<p>By learning html, I'll be able to create webpages like a
<del>beginner</del>
which I am of course.</p>
</body>
</html>

HTML Colors
Color Values
Colors are defined using a hexadecimal notation for the combination of red, green, and blue
color values (RGB). The lowest value that can be given to one light source is 0 (hex #00).
The highest value is 255 (hex #FF). This table shows the result of combining red, green, and
blue:

Color Color HEX Color RGB


#000000 rgb(0,0,0)
#FF0000 rgb(255,0,0)
#00FF00 rgb(0,255,0)
#0000FF rgb(0,0,255)
#FFFF00 rgb(255,255,0)
#00FFFF rgb(0,255,255)
#FF00FF rgb(255,0,255)
#C0C0C0 rgb(192,192,192)
#FFFFFF rgb(255,255,255)

Color Names
A collection of color names is supported by most browsers. To view a table of color names
that are supported by most browsers visit this web page:
http://profdevtrain.austincc.edu/html/color_names.htm

Note: Only 16 color names are supported by the W3C HTML 4.0 standard (aqua, black,
blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and
yellow). For all other colors you should use the Color HEX value.
9|Page Internet and Web Development
Color Color HEX Color Name
#F0F8FF AliceBlue
#FAEBD7 AntiqueWhite
#7FFFD4 Aquamarine
#000000 Black
#0000FF Blue
#8A2BE2 BlueViolet
#A52A2A Brown

HTML Lists
HTML provides a simple way to show unordered lists (bullet lists) or ordered lists
(numbered lists).
Unordered Lists
An unordered list is a list of items marked with bullets (typically small black circles). An
unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
This Code Would Display
<ul>
<li>Coffee</li>  Coffee
<li>Milk</li>  Milk
</ul>

Ordered Lists
An ordered list is also a list of items. The list items are marked with numbers. An ordered
list starts with the <ol> tag. Each list item starts with the <li> tag.

This Code Would Display


<ol>
<li>Coffee</li> 1. Coffee
<li>Milk</li> 2. Milk
</ol>

Inside a list item you can put paragraphs, line breaks, images, links, other lists, etc.
Definition Lists
Definition lists consist of two parts: a term and a description. To mark up a definition list,
you need three HTML elements; a container <dl>, a definition term <dt>, and a definition
description <dd>.

This Code Would Display


<dl>
<dt>Cascading Style Sheets</dt>
<dd>Style sheets are used to Cascading Style Sheets
provide presentational Style sheets are used to provide presentational
suggestions for documents marked suggestions for documents marked up in HTML.
up in HTML.
</dd>
</dl>

10 | P a g e I n t e r n e t a n d W e b D e v e l o p m e n t
Inside a definition-list definition (the <dd> tag) you can put paragraphs, line breaks,
images, links, other lists, etc.
Try It Out
Open your text editor and type the following:
<html>
<head>
<title>My First Webpage</title>
</head>
<body bgcolor="#EDDD9E">
<h1 align="center">My First Webpage</h1>
<p>Welcome to my <strong>first</strong> webpage. I am writing
this page using a text editor and plain old html.</p>
<p>By learning html, I'll be able to create web pages like a
pro....<br>
which I am of course.</p> Here's what I've learned:
<ul>
<li>How to use HTML tags</li>
<li>How to use HTML colors</li>
<li>How to create Lists</li>
</ul>
</body>
</html>

HTML Links
HTML uses the <a> anchor tag to create a link to another document or web page.
The Anchor Tag and the Href Attribute
An anchor can point to any resource on the Web: an HTML page, an image, a sound file, a
movie, etc. The syntax of creating an anchor:
<a href="url">Text to be displayed</a>.The <a> tag is used to create an anchor to
link from, the href attribute is used to tell the address of the document or page we are
linking to, and the words between the open and close of the anchor tag will be displayed as a
hyperlink.

This Code Would Display


<a href="http://www.austincc.edu/">Visit Visit ACC!
ACC!</a>
The Target Attribute
With the target attribute, you can define where the linked document will be opened. By
default, the link will open in the current window. The code below will open the document in
a new browser window:

<a href=http://www.austincc.edu/ target="_blank">Visit ACC!


</a>

Email Links
To create an email link, you will use mailto: plus your email address. Here is a link to
ACC's Help Desk:

<a href="mailto:[email protected]">Email Help Desk</a>


To add a subject for the email message, you would add ?subject= after the email
address. For example:
11 | P a g e I n t e r n e t a n d W e b D e v e l o p m e n t
<a href="mailto:[email protected]?subject=Email
Assistance">Email Help Desk</a>
The Anchor Tag and the Name Attribute
The name attribute is used to create a named anchor. When using named anchors we can
create links that can jump directly to a specific section on a page, instead of letting the user
scroll around to find what he/she is looking for. Unlike an anchor that uses href, a named
anchor doesn't change the appearance of the text (unless you set styles for that anchor) or
indicate in any way that there is anything special about the text. Below is the syntax of a
named anchor:

<a name="top">Text to be displayed</a>


To link directly to the top section, add a # sign and the name of the anchor to the end of a
URL, like this:

This Code Would Display


<a
href="http://profdevtrain.austincc.e
du/html Back to top of page
/10links.html#top">Back to top of
page </a>

A hyperlink to the top of the page


from within the file 10links.html

Named anchors are often used to create "table of contents" at the beginning of a large
document. Each chapter within the document is given a named anchor, and links to each of
these anchors are put at
the top of the document. If a browser cannot find a named anchor that has been specified, it
goes to the top of the document. No error occurs.

HTML Images
The Image Tag and the Src Attribute
The <img> tag is empty, which means that it contains attributes only and it has no closing
tag. To display an image on a page, you need to use the src attribute. Src stands for "source".
The value of the src attribute is the URL of the image you want to display on your page. The
syntax of defining an image:

This Code Would Display

<img src="graphics/chef.gif">

Not only does the source attribute specify what image to use, but where the image is located.
The above image, graphics/chef.gif, means that the browser will look for the image name
chef.gif in a graphics folder in the same folder as the html document itself.

12 | P a g e I n t e r n e t a n d W e b D e v e l o p m e n t
src="chef.gif" means that the image is in the
same folder as the html document calling for it.

src="images/chef.gif" means that the image


is one folder down from the html document that
called for it. This can go on down as many layers as
necessary.

src="../chef.gif" means that the image is in


one folder up from the html document that called for
it.

src="../../chef.gif" means that the image


is two folders up from the html document that called
for it.

src="../images/chef.gif" means that the


image is one folder up and then another folder down
in the images directory.

src="../../../other/images/chef.gif"
means this goes multiple layers up.

The browser puts the image where the image tag occurs in the document. If you put an
image tag between two paragraphs, the browser shows the first paragraph, then the image,
and then the second paragraph.

The Alt Attribute


The alt attribute is used to define an alternate text for an image. The value of the alt attribute
is author-defined text:
<img src="graphics/chef.gif" alt="Smiling Happy Chef ">
The alt attribute tells the reader what he or she is missing on a page if the browser can't load
images. The browser will then display the alternate text instead of the image. It is a good
practice to include the alt attribute for each image on a page, to improve the display and
usefulness of your document for people who have text-only browsers or use screen readers.

13 | P a g e I n t e r n e t a n d W e b D e v e l o p m e n t
Image Dimensions
When you have an image, the browser usually figures out how big the image is all by itself.
If you put in the image dimensions in pixels however, the browser simply reserves a space
for the image, then loads the rest of the page. Once the entire page is loads it can go back
and fill in the images. Without dimensions, when it runs into an image, the browser has to
pause loading the page, load the image, then continue loading the page. The chef image
would then be:

<img src="graphics/chef.gif" width="130" height="101"


alt="Smiling Happy Chef">
Open the file mypage2.html in your text editor and add code highlighted in bold:

<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1 align="center">My First Web page</h1>
<p>Welcome to my first webpage. I am writing this page using a text editor and plain old
html.</p>
<p>By learning html, I'll be able to create web pages like a pro....<br>
which I am of course.</p>
<!-- Who would have guessed how easy this would be :) -->
<p><img src="graphics/chef.gif" width="130" height="101" alt="Smiling Happy Chef"
align="center"></p>
<p align="center">This is my Chef</p>
</body>
</html>

HTML Music (Audio) and Video Codes


Music and video can easily be inserted onto web page in a relatively
easy way by using the embed <embed> tags. In the past, multiple tags
had to be used because browsers did not have a uniform standard for
defining embedded media files. A src attribute is required to define the
correct URL (local or global) of the audio or video file in order for it to
be displayed correctly. Other attributes can be set in order to customize
your web pages.

Example: HTML Code for Music


(Audio)
<embed src="nounanthems.mid" />

Example: HTML Code for Video


<embed src="http:// universitymedia.com
/files/noun.mpeg"/>

Listing of Video Media


Types
14 | P a g e I n t e r n e t a n d W e b D e v e l o p m e n t
Below is the list of the most commonly used file formats for the
internet.
•.swf files - are the file types created by Macromedia's Flash
program.
• .wmv files - are Microsoft Window’s Media Video file types.
• .mov files - are Apple's Quick Time Movie format.
• .mpeg files - set the standard for compression movie files created
by the Moving Pictures Expert Group.

Flash movies (.swf), AVI's (.avi), and MOV's (.mov) file types are supported by the embed
tag. The “.mpeg" files and Macromedia's “.swf” files are the most compact and widely used
for the design of web pages.

Tables
Tables are defined with the <table> tag. A table is divided into rows (with the <tr> tag),
and each row is divided into data cells (with the <td> tag). The letters td stands for "table
data," which is the content of a data cell. A data cell can contain text, images, lists,
paragraphs, forms, horizontal rules, tables, etc.
<table border="1" >
<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>
How it looks in a browser:

row 1, cell 1 row 1, cell 2


row 2, cell 1 row 2, cell 2

1. Tables and the Border Attribute


If you do not specify a border attribute the table will be displayed without any borders.
Sometimes this can be useful, but most of the time, you want the borders to show.

To display a table with borders, you will have to use the border attribute:

<table border="1">
<tr>
<td>Row 1, cell 1</td>
<td>Row 1, cell 2</td>
</tr>
</table>

2. Headings in a Table
Headings in a table are defined with the <th> tag.

<table border="1">
15 | P a g e I n t e r n e t a n d W e b D e v e l o p m e n t
<tr>
<th>Heading</th>
<th>Another Heading</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>
How it looks in a browser:

Heading Another Heading


row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2

3. Empty Cells in a Table


Table cells with no content are not displayed very well in most browsers.

<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td></td>
</tr>
</table>
How it looks in a browser:

row 1, cell 1 row 1, cell 2


row 2, cell 1
Note that the borders around the empty table cell are missing (NB! Mozilla Firefox displays
the border).

To avoid this, add a non-breaking space (&nbsp;) to empty data cells, to make the borders
visible:

<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>&nbsp;</td>
</tr>
16 | P a g e I n t e r n e t a n d W e b D e v e l o p m e n t
</table>
How it looks in a browser:

row 1, cell 1 row 1, cell 2


row 2, cell 1

Table Tags
Tag Description
<table> Defines a table
<th> Defines a table header
<tr> Defines a table row
<td> Defines a table cell
<caption> Defines a table caption
<colgroup> Defines groups of table columns
<col> Defines the attribute values for one or more columns in a table
<thead> Defines a table head
<tbody> Defines a table body
<tfoot> Defines a table footer

Table Size
Table Width
The width attribute can be used to define the width of your table. It can be defined as a fixed
width or a relative width. A fixed table width is one where the width of the table is specified
in pixels. For example, this code, <table width="550">, will produce a table that is
550 pixels wide. A relative table width is specified as a percentage of the width of the
visitor's viewing window. Hence this code, <table width="80%">, will produce a
table that occupies 80 percent of the screen.

This table width is 250 pixels

This table width is 50%

HTML Layout - Using Tables


One very common practice with HTML, is to use HTML tables to format the layout of an
HTML page.
A part of this page is formatted with two columns. As you can see on this page, there
is a left column and a right column.
This text is displayed in the left column. An HTML <table> is used to divide a part of this
Web page into two columns.
The trick is to use a table without borders, and maybe a little extra cell-padding.
No matter how much text you add to this page, it will stay inside its column borders.
Try It Out!
Let's put everything you've learned together to create a simple page. Open your text editor
and type the following text:

<html>
<head>
<title>My First Web Page </title>
</head>
17 | P a g e I n t e r n e t a n d W e b D e v e l o p m e n t
<body>
<table width="90%" cellpadding="5" cellspacing="0" >
<tr bgcolor="#EDDD9E">
<td width="200" valign="top"><img src="graphics/contact.gif"
width="100" height="100"></td>
<td valign="top"><h1 align="right">Janet Doeson</h1>
<h3 align="right">Technical Specialist</h3></td>
</tr>
<tr>
<td width="200">
<h3>Menu</h3>
<ul>
<li><a href="home.html">Home</a></li>
<li> <a href="faq.html">FAQ</a></li>
<li> <a href="contact.html">Contact</a></li>
<li> <a href="http://www.austincc.edu">Links</a> </li>
</ul></td>
<td valign="top"><h2 align="center">Welcome!</h2>
<p>Welcome to my first webpage. I created this webpage
without the assistance of a webpage editor. Just my little
text editor and a keen understanding of html.</p>
<p>Look around. Notice I'm able to use paragraphs, lists and
headings. You may not be able to tell, but the layout is done
with a table. I'm very clever. </p>
<blockquote>
<p>I always wanted to be somebody, but now I realize I should
have been more specific.</p>
<cite>Lily Tomlin </cite> </blockquote> </td>
</tr>
</table>
<hr width="90%" align="left">
<address>
Janet Doeson<br> Technical Specialist<br>
512.555.5555
</address>
<p>Contact me at <a
href="mailto:[email protected]">[email protected]</a>
</p></body>
</html>

Colspan and Rowspan Attributes

1.The colspan Attribute: This attribute specifies the number of columns that a cell will occupy. It
is also used to merge two or more columns into a single column.
2.The rowspan attribute: This attribute specifies the number of rows that a cell will occupy. The
rowspan attribute is used to merge two or more rows.
Figure 3.3 shows a table with rowspans=2 and colspan=3
<table border="1">
<tr>
<th>Column 1</th>
<th>Column 2</th>
18 | P a g e I n t e r n e t a n d W e b D e v e l o p m e n t
<th>Column 3</th>
</tr>
<tr><td rowspan="2">Row 1 Column1</td>
<td>Row 1 Column2</td><td>Row 1 Column3</td></tr>
<tr><td>Row 2 Column2</td><td>Row 2 Column3</td></tr>
<tr><td colspan="3">Row 3 Column1</td></tr>

</table>

This will produce following result:

Column 1 Column 2 Column 3


Row 1 Column2 Row 1 Column3
Row 1 Column1
Row 2 Column2 Row 2 Column3
Row 3 Column1

Create Your Own Page

It’s time to create your own page. Use your text editor to create a page which contains the
following:
• the required HTML page codes
• link to another web page
• an email link
• a picture/graphic
• a list of information

What is a Form ?
Forms are a simple way that a person viewing your Web page can send your data. This is
done by the user filling in various parts or input lines within the form . HTML forms are used
to pass data to a server.

An HTML form can contain input elements like text fields, checkboxes, radio-buttons,
submit buttons and more. A form can also contain select lists, textarea, fieldset, legend,
and label elements.

The <form> tag is used to create an HTML form:


<form>

input elements
.
</form>

Tag Description

<form> Defines an HTML form for user input

<input> Defines an input control

<textarea> Defines a multiline input control (text area)

19 | P a g e I n t e r n e t a n d W e b D e v e l o p m e n t
<label> Defines a label for an <input> element

<fieldset> Groups related elements in a form

<legend> Defines a caption for a <fieldset> element

<select> Defines a drop-down list

<optgroup> Defines a group of related options in a drop-down list

<option> Defines an option in a drop-down list

<button> Defines a clickable button

Forms are supported by almost every browser and make it possible to create documents that
collect and process user input and formulate personalized replies. Once a user fills out a form,
it is submitted to a server or e-mailed to a specific address. If sent to a server, that server
passes that information to a supporting program or application that processes the data.

The Form Element


The <form> tag is used to specify the beginning of a form area on a Web page while
the </form> tag is used to specify the end of a form area. Common attributes used to the
<form> tags are name, method, and action. These attributes are used to specify what server-
side program or file will process the form, how the form information will be sent to the
server, and the name of the form.

1. Name Attribute: This is an optional attribute and names the form. The name of the form
is required for it to be easily access by client scripting languages, such as JavaScript (will
be treated latter) to edit and verify the form prior to sending its information for server-side
processing.

2. Method Attribute: Another attribute of the FORM tag is the METHOD, which is how the
form input will be sent to the gateway. The method can be either " GET " or " POST ".
 Post means to send the form entry results as an e-mail document. POST is specified for the
attribute, it transmits the form data in the body of the HTTP response. This is the most
common method.
 Get is usually used with search engines and also GET is specified, it causes the form data to
be appended to the URL.This attribute is optional.

3. Action Attribute: This attribute is optional. However, when a value is specified it


determines the server-side program or script that will process your form data using CGI. The
value should be a valid file name on a Web server. Examples PHP script(.php extension),
Sun JavaServer Pages(.jsp extension), Microsoft Active Server Pages(.asp extension).

Example 1: HTML Code for Form


<FORM action="process.php” method="post">
<P>
First name: <INPUT type="text" name="firstname"><BR> Last name: <INPUT
type="text" name="lastname"><BR> Department: <INPUT type="text"
name="dept"><BR>
<INPUT type="radio" name="gender" value="Male"> Male <BR>
<INPUT type="radio" name="gender" value="Female"> Female <BR>
<INPUT type="submit" value="Send"> <INPUT type="reset" value=”Reset”>
20 | P a g e I n t e r n e t a n d W e b D e v e l o p m e n t
</P>
</FORM>
Output

Fig. 4. 1: Form Display on Browser

3.2 HTML – Text Field/Box

Text fields are small rectangles that allow a user to simply input some text
or numeric information, such as names, e-mail addresses, phone number, and
other text and submit the information to the web server. The form element
is configured by the <input /> tag. Common attributes of a text box are type,
size, maxlength, value and password.

HTML – Text Field Size

You can control the size of the text area by specifying the size attribute. The
example below provides three different sizes for your text fields. The
default size is usually around 20 characters long. See example 2

Example 2: HTML Code for Input / Text Box Element


<html>
<body>
<FORM action="process.php” method="post">
<P>
First name: <INPUT type="text" name="firstname" size="20"><BR>
Last name: <INPUT type="text" name="lastname" size="19"><BR>
Department: <INPUT type="text" name="dept" size="15"><BR> </P>
</FORM>
<body>
<html>

Output

First name:
Last name:
Department:

Fig. 4. 2: Textbox

HTML –TextField Maxlength


When the value is specified, TextField Maxlength is used to limit the number of
characters a user can type into fields. It is a good programming practice to
specify the maxlength; generally, this should match the size of your field.
21 | P a g e I n t e r n e t a n d W e b D e v e l o p m e n t
Example 3: HTML Code Textbox with Maxlength Attribute
<html>
<body>
<FORM action="process.php” method="post">
<P>
First name: <INPUT type="text" name="firstname" size="20" maxlength="20"><BR>
Last name: <INPUT type="text" name="lastname" size="20" maxlength="20"><BR>
Department: <INPUT type="text" name="dept" size="15" maxlength="15"><BR>
</P>
</FORM>
<body>
<html>

Practice 1
Run the program and attempt to enter data more than the maximum length specified. Write
down your experience in a sentence

HTML –TextField Value

The value attribute is used to pre-populate your text fields with some information. This
can then be manipulated with any scripting language such as PHP, PERL, etc. See example 4
below.

Example 4: HTML Code for TextField value


<html>
<body>
<FORM action="process.php” method="post">
<P>
First name: <INPUT type="text" name="firstname" size="20" maxlength="20" value="Fresh"><BR>
Last name: <INPUT type="text" name="lastname" size="20" maxlength="20" Value="Senior"><BR>
Department: <INPUT type="text" name="dept" size="15" maxlength="15" Value="Computer
Sc."><BR>
</P>
</FORM>
<body>
<html/>

3.3 HTML – Password Field

Password fields are a special type of <input /> tag. To implement them,
change the type attribute from text to password. Password field is used to
accept information that need to be hidden as it is entered. When a user types in
information in a password box, asterisks (i.e *) are displayed instead of the
characters that are being typed. This does not mean that the data entered is
encrypted. To encrypt data one must use a scripting language to process the
data captured. See example 5 below.

Example 5: Password Attribute


HTML Code:
<html>
<body>
22 | P a g e I n t e r n e t a n d W e b D e v e l o p m e n t
<FORM action="process.php” method="post">
<P>
MatNo: <INPUT type="text" name="matno" size="11" maxlength="11"><BR>
User Name: <INPUT type="text" name="username" size="20" maxlength="20"><BR>

23 | P a g e I n t e r n e t a n d W e b D e v e l o p m e n t
Password: <INPUT type="password" name="pass" size="8" maxlength="8"><BR>
</P>
</FORM>
<body>
<html>
NOU123564
MatNo:
Okeke
User Name:
********
Password:
Fig. 4. 4: Password Fields

3.4 HTML – Checkbox Forms

Checkboxes are another type of <input /> form. They are used for instances where a user
may wish to select some or all-multiple options. The “type” attribute must be set to checkbox and
set the name and value attributes. A sample checkbox code and the corresponding form are
shown in Example 6 and Figure 5 below.

Example 6: HTML Code for Checkbox

<html>
<body>
<FORM action="process.php” method="post">
<P>
<p>Please select the courses to register for the semester.</p>
CIT313: <input type="checkbox" name="courses" value="CIT313" /><br />
CIT314: <input type="checkbox" name="courses" value="CIT314" /><br />
CIT315: <input type="checkbox" name=" courses" value="CIT315" /><br />
EDU325: <input type="checkbox" name="courses" value="EDU325" /><br/>
</P>
</FORM>
<body>
<html>
HTML –Checkboxes selected

With checkboxes, it is possible to pre-check the input boxes for viewers using the checked
attribute. For example if the course CIT 313 is a compulsory course for all the students, it can be
pre-checked. To implement this, simply set the checked attribute to “yes”. The codes for
implementing checkboxes selected and the corresponding output are shown in example 7 and
Figure 5 respectively.

Example 7: HTML Cod for Checkbox selected


<p>Please select the courses you want to register for the semester.</p>
CIT313: <input type="checkbox" checked =”yes” name="courses" value="CIT313" /><br />
CIT314: <input type="checkbox" name="courses" value="CIT314" /><br />
CIT315: <input type="checkbox" name=" courses" value="CIT315" /><br />
EDU325: <input type="checkbox" name="courses" value="EDU325" /><br/>
</P>

24 | P a g e Internet and web development


Output
Fig. 4.5: Checkbox selected

3.5 HTML –Radio Form

Radios are types of input forms that allow a user to select exactly one item from a group of
predetermined items. In order to achieve this, we must properly name each radio button selection
accordingly. Thus, each radio button in a group is given the same name and a unique value. The
codes for implementing radio buttons and the corresponding output are shown in example 8 and
Figure 6 respectively.

Example 9: HTML Code for Radio Button

Economics: <input type="radio" name="department” />


Computer Science: <input type="radio" name="department" /> Accounting: <input
type="radio" name="department" />

Economics:
Computer Science:
Accounting:

Fig. 4.6: Radio Button


By naming these three radios “department,” they are identified as being related by the browser.

HTML –Radio Checked


By using the checked attribute, you will be able to configure the radio button to be selected by default
when displayed by the browser. Example 10 shows the codes for Radio Checked while Figure 7 shows
the corresponding output on a browser.

Example 10: HTML Code for Radio Checked


Economics: <input type="radio" name="department” checked="yes" />
Computer Science: <input type="radio" name="department" />
Accounting: <input type="radio" name="department" />
Economics:
Computer Science: Accounting:

3.6 HTML - Textarea

This allows multi text field to be entered by a user. Paragraphs, essays, questions, descriptions or
memos can be cut and pasted into textareas and submitted. Textareas have an opening tag
<textarea> and a closing tag </textarea>. Example 11 and Figure 8 show the codes and the output
of textarea on a browser respectively.

Example 3: HTML Code for Textarea


<textarea>Dire Dawa Institute of Technology!</textarea>

25 | P a g e Internet and web development


Nat al Open Univers
io ity of Nig

Fig 4.7: Textarea

HTML – Text area Col and Rows

To adjust the size of the appearance of the text area requires two attributes, cols and rows with
numeric values. The larger the value the larger the field will appear. Example 12 is a sample code
for implementing text area col and row.

Example 12: HTML Code for col and row in textarea

<textarea cols="30" rows="10">Text Area!</textarea>


<textarea cols="10" rows="2">Text Area!</textarea>
<textarea cols="25" rows="5">Text Area!</textarea>

3.7 HTML –Selection Forms and Drop Down Lists

Drop down lists are the basic selection forms. The <select> container tag along with the <option>
tags are used to configure the select list. Other names used to describe the drop down list are
select list, select box, drop-down box, and option box. Drop down lists have several options a
user can select. A sample code to implement drop down list and the corresponding output on a
browser are shown in example 13 and Figure 9.

Example 13: HTML Code for Drop Down List


<select>
<option>Economic </option>
<option>Computer Science </option>
<option>Accounting </option>
</select>
By default, the first coded <option> will be displayed or selected as the default. We can change
this using the selected attribute.

Example 14: HTML Code for Drop Down list with selected attribute
<select>
<option>Economic </option>
<option>Computer Science </option>
<option selected=”yes”>Accounting </option>
</select>

Fig.4.8: Drop Down list

26 | P a g e Internet and web development


Hidden

A Hidden input is a name/value pair that is returned to you but does not
show up anywhere on the web page. The text for a Hidden input is simple.

<INPUT type="hidden" name="Location" value="USA Form">


3.8 Submit Button

Submit
Submission buttons are a type of <input /> tag and is used to submit the form. To achieve form submission,
set the type attribute to submit. This creates a special type of button in forms that will cause the browser to
send the form data to the web server provided there are available server scripting codes to achieve this.

HTML – Reset Button

Reset
Reset buttons exist to reset the fields of a form to its initial vales. See the codes in example 14.

Example 14: HTML Code for Submit and Reset Buttons

<input type="submit" value="Submit" /><br />


<input type="Reset" value="Reset" /><br />
Notice that in the above example we also changed what was written on our button using the value attribute. This can
be changed to any value you wish.

Frames
Frames are an easy way to make any page look more professional. The frame commands tells the browser to
split the screen into two or more parts, each with a separate web page. To do this we need to create a web page
with the commands to tell the browser how to split the screen. You begin
with the FRAMESET section which is in place of the BODY section.

<HTML>
<HEAD>
<TITLE>Sample </TITLE>
</HEAD>
<FRAMESET COLS="25%,*">
<FRAME SRC="pageone.html">
<FRAME SRC="pagetwo.html">
</FRAMESET>
</HTML>

In this FRAMESET tag we tell the browser to split the window vertically with the attribute COLS. There will
be two pages shown. The first one taking up 25% of the screen, and the second one taking up the remainder of
the screen. To split the window horizontally, use the ROWS attribute.

27 | P a g e Internet and web development


<FRAMESET ROWS="75%,*">
<FRAME SRC="pageone.html">
<FRAME SCR="pagetwo.html">
</FRAMESET>

We also need to tell the browser the names (URLs) of the web pages to go into the separate windows. The
FRAME command tells the browser the location of the page to be viewed in a particular frame. The first page
source will be displayed on the left column or the top row and the remaining pages will follow.
Frames can be used as a navigational tool for the users to browse through our pages. To do this we need to
create several web pages. One page to hold the navigational links on the left, one as the default page and a
couple to practice navigating. First, to generate the page that tells how to set up the frames, enter the
following. Save this file as "Frame.html".

<HTML>
<HEAD>
<TITLE>Start Frames </TITLE>
</HEAD>
<FRAMESET COLS="20%,*">
<FRAME SRC="Contents.html">
<FRAME SRC="Default.html" name="main">
</FRAMESET>
</HTML>

This will create the main page that will hold our other pages in its frames. Naming the second, or right hand
window frame "main" will allow us to switch this frame for others depending on which link our users click on.

Now we need to create a page that will be held in the larger right window as the default
before the user selects which page to view. Enter the following text. Save this file as
"Default.html".

<HTML>
<HEAD>
<TITLE> My Default Page </TITLE>
</HEAD>
<BODY bgcolor="white">
<FONT size=6 color="blue">
<CENTER>
This is my main page.
<P> From here you will be able to navigate to my different sites by choosing my links on the left.
</CENTER>
</BODY>
</HTML>

Now we need to create the Contents page. This page will be seen in the first or left hand window. Enter the
following into Notepad and save as "Contents.html".

<HTML>
<HEAD>
<TITLE> My Contents Page </TITLE>
</HEAD>
<BODY BGCOLOR="yellow">
28 | P a g e Internet and web development
<B> Pick An Animal </B>
<P><A HREF="dog.html" TARGET=main>DOG</A>
<P><A HREF="cat.html" TARGET=main>CAT</A>
<P><A HREF="bird.html" TARGET=main>BIRD</A>
<P>
</BODY>
</HTML>

Within each anchor tag notice the "TARGET=main" addition. This tells the browser to put the page signified
by the link address into the Frame named "Main". You may choose any name you wish, but it must match. For
time saving purposes, the pages dog.html, cat.html, and bird.html are
already on your lab computer. Please copy them and the images with the same names, to wherever your html
file is located. Once all this is done, you should get the following:

29 | P a g e Internet and web development

You might also like