HTLM Intro
HTLM Intro
HTLM Intro
Learning Objectives
HTML, which stands for HyperText Markup Language, is a markup language used to create web
pages it is not a programming language like Java. The basic function of the HTML is to describe the
standard (—) how a browser should display text and multimedia elements such as graphics, animation,
etc. It works on a limited number of tags and is not difficult to learn and use. Let us learn how it works.
The web developer uses "HTML tags" to format different parts of the document. For example,
you use HTML tags to specify headings, paragraphs, lists, tables, images and much more.
HTML is a subset of Standard Generalized Markup Language (SGML) and is specified by the
World Wide Web Consortium (W3C).
The HTML is platform independent that is computer and computer operating system on
which it is running. It means that HTML uses a small number of tags to create Web page.
Any Web server regardless of their location and operating system can publish these web
pages. These web pages can also be viewed or displayed by any Web browser regardless
of the platform on which it is running.
As we have discussed, HTML works on tags. These HTML tags control the page
structure and the style sheet controls the details about page layout and their presentation.
1
In other words, HTML style sheet provides consistency and creativity to create
professional quality web pages.
The basic structure of using tag is <tag_name> some text </tag_name>. For example, the
tag for making text bold is <b> this is bold </b>. And when displayed in a browser it
will be displayed, as this is bold.
Web page is made up of two sections: head and body. Each of these sections is enclosed
within a pair of <html> tags. The head section describes the page content while the body
section defines the web page look and feel. Most of HTML tags are used in the body
section, whereas the number of tags is limited in the head section. The standard web page
structure in HTML is
<html>
<head>
<title>Title of the page is given here</title>
</head>
<body>
web page contents go here
</body>
</html>
You don't need any special equipment or software to create HTML. In fact, you probably already
have everything you need. Here is what you need:
Computer
Text or HTML editor. Most computers already have a text editor and you can easily
create HTML files using a text editor. Most computers already have a text editor.
Examples of text editors include Notepad (for Windows), Pico (for Linux), or
Simpletext/Text Edit/Text Wrangler (Mac).
2
Web Browser. For example, Internet Explorer or Firefox.
NB No, you do not need to be online to create web pages. You can create web pages on your
local machine. You only need to go online when you want to publish your web page to the web -
this bit comes later.
An HTML file is simply a text file saved with an .html or .htm extension (i.e. as opposed
to a .txt extension).
a. Open up your computer's normal plain text editor (this will probably be Notepad
if you're using Windows or TextEdit if you're using a Mac). You could use a
specialized HTML editor such as DreamWeaver or FrontPage if you prefer.
Either...
4. Repeat the last 2 steps until you're satisfied with the result
It's unrealistic to expect that you will always get it right the first time around. Don't worry
- that's OK! Just try again and again - until you get it right.
3
HTML Documents = Web Pages
The purpose of a web browser (like Internet Explorer or Firefox) is to read HTML documents
and display them as web pages. The browser does not display the HTML tags, but uses the tags
to interpret the content of the page:
An element consists of three basic parts: an opening tag, the element's content, and finally, a
closing tag.
Every (web)page requires four critical elements: the html, head, title, and body elements.
The<html>Element..</html>
<html> begins and ends each and every web page. Its sole purpose is to encapsulate all the
HTML code and describe the HTML document to the web browser. Remember to close your
HTML documents with the corresponding </html> tag at the bottom of the document.
4
The <head> Element
The head functions "behind the scenes." Tags placed within the head element are not directly
displayed by web browsers.
HTML Code:
<html>
<head>
</head>
</html>
Place the <title> tag within the <head> element to title your page. The words you write between
the opening and closing <title></title> tags will be displayed at the top of a viewer's browser.
Here's the html code:
HTML Code:
<html>
<head>
<title>My WebPage!</title>
</head>
</html>
The <body> element is where all content is placed. (Paragraphs, pictures, tables, etc). As the
menu on the left suggests, we will be looking at each of these elements in greater detail as the
module progresses. For now, it is only important to understand that the body element will
encapsulate all of your webpage's viewable content.
5
HTML Code:
<html>
<head>
<title>My WebPage!</title>
</head>
<body>
Hello World! All my content goes here!
</body>
</html>
www.w3schools.com
6
HTML EXERCISE 1
Create a HTML document in your text editor with the contents shown below and save it as
exer1.htm and then open it in a web browser.
<html>
<head>
<title>Exercise 1</title>
</head>
<body>
This is my first web page! Have a look!
</body>
</html>
HTML EXERCISE 2
Create a web that will display as shown below when opened in a Web browser.
7
CHAPTER FIVE
FORMATTING TAGS
Learning Objectives
There is a special tag for specifying headings in HTML. There are 6 levels of headings in HTML
ranging from h1 for the most important, to h6 for the least important.
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
Results in this:
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
8
5.2 Using Bold, Italics and Underline tags
Bold
Results in this:
Italics
Results in this:
Underlining
Results in this:
9
Example
<p>This is a paragraph</p>
<p>This is another paragraph</p>
Note: Browsers automatically add an empty line before and after a paragraph.
Line Breaks
Use the <br /> tag if you want a line break (a new line) without starting a new paragraph:
Results in this:
Here is a
line break.
Horizontal Rule
Results in this:
10
5.4 Typefaces and colors
Specifying Typefaces
When styling text with fixed or relative type style tags, browsers display the text in the default
typeface. The default is set in the user preferences and control text color by including the
FACE= and color = arguments within the <font tag.
Note that the font you choose must be installed on the user‘s system, not just yours. If they are
not installed the browser will still display the text in the default typeface. The font face is
specified as follows
<font Face =‖Arial‖>
Using colors
The text colors are specified in the <FONT tag with the COLOR=argument
Example
</Font color=‖blue‖>
Both the typeface and the font color can be specified in the font tag at the same time as shown
below
example
<html>
<head>
</head>
<body>
<br>
11
</body>
</html>
BODY colors
The colors of the background and text of the text page can be set by the BGCOLOR and TEXT
options in the BODY tag.
Color Names
The most common methods for specifying colors are by using the color name or the hexadecimal
value. Although color names are easier to remember, the hexadecimal values and RGB values
provides you with more color options.
Hexadecimal values are a combination of letters and numbers. The numbers go from 0 - 9 and
the letters go from A to F. When using hexadecimal color values in your HTML/CSS, you
preceed the value with a hash (#). Although hexadecimal values may look a little weird at first,
you'll soon get used to them.
There are 16 color names (as specified in the HTML 4.0 specification). The chart below shows
these color names and their corresponding hexadecimal value.
Color Color Name Hexadecimal Value Color Color Name Hexadecimal Value
12
Red #ff0000 Blue #0000ff
You can make up your own colors by simply entering any six digit hexadecimal value
(preceeded by a hash). In the following example, we're using the same code as above. The only
difference is that, instead of using "blue" as the value, we're using its hexadecimal equivalent
(which is #0000ff):
<html>
<head>
</head>
<font color=‖#FF0000‖>
<H2>Gnomic sayings</h2>
<font color=‖#0000FF‖>
<H2>Gnome computing</h2>
</body>
</html>
13
Chapter review Exercise
HTML Exercise 3
Create a web page that will display on the browser as shown below
www.w3schools.com
14
INTERMEDIATE
DESIGNER TAGS
Learning Objectives
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.
When you move the cursor over a link in a Web page, the arrow will turn into a little hand.
Example
<a href="http://www.mku.ac.ke/">Visit Mount Kenya</a>
15
which will display like this: Visit mount Kenya
Tip: The "Link text" doesn't have to be text. You can link from an image or any other HTML element.
The <img> tag is empty, which means that it contains attributes only, and 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.
The browser displays the image where the <img> 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 required alt attribute specifies an alternate text for an image, if the image cannot be
displayed.
The alt attribute provides alternative information for an image if a user for some reason cannot
view it (because of slow connection, an error in the src attribute, or if the user uses a screen
reader).
16
Determining your image size
The size of your image can be assigned by using the width and the height values as shown below
A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the
<td> tag). td stands for "table data," and holds the content of a data cell. A <td> tag can contain
text, links, images, lists, forms, other tables, etc.
Table Example
<html>
<head>
</head>
<body>
<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>
</body>
</html>
17
How the HTML code above looks in a browser:
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.
<table border="1">
<tr>
<td>Row 1, cell 1</td>
<td>Row 1, cell 2</td>
</tr>
</table>
<html>
<head>
</head>
<body>
<table border="1">
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>row 1, cell 1</td>
18
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
</table>
</body>
</html>
Header 1 Header 2
Adding Captions
Captions can be added to the table by using the <caption> tag as shown in the example below;
<html>
<head>
<body>
<table border="1">
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
19
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
</body>
</html>
Monthly savings
Month Savings
January $100
February $50
20
6.3 Lists
The most common HTML lists are ordered and unordered lists:
HTML Lists
An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
The list items are marked with bullets (typically small black circles).
<ul>
<li>Coffee</li>
<li>Milk</li>
</ul>
Coffee
Milk
<html>
<body>
<h4>An Unordered List:</h4>
<ul type="square">
<li>Coffee</li>
<li>Tea</li>
21
<li>Milk</li>
</ul>
</body>
</html>
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
<ol>
<li>Coffee</li>
<li>Milk</li>
</ol>
1. Coffee
2. Milk
<html>
<body>
<h4>Numbered list:</h4>
<ol>
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ol>
The <dl> tag is used in conjunction with <dt> (defines the item in the list) and <dd> (describes
the item in the list):
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
Coffee
Milk
23
Chapter review Exercise
HTML Exercise 4
Create a web page that will display on the browser as shown below
www.w3schools.com
24
Solutions to exercises
HTML Exercise 2
<html>
<head>
<title>home</title>
</head>
<body>
Creating web pages is fun!!!
</body>
</html>
HTML Exercise 3
<html>
<head>
<title> Home Page </title>
</head>
<body bgColor = “#008000” TEXT = “#800000”>
<H1>MOUNT KENYA UNIVERSTITY</h1> <hr />
<font color=”#000000”>
<H2>Your University of Choice</h2>
<b>Our Vision</b>
<p> To be a centre of excellence in training, research and innovation in Science &
Technology in Africa
<p> <b> Our Mission</b>
<p> To attain world class standards in training and innovation for sustainable
individual prosperity and social development.
<p> <b> Our Philosophy</b>
<p> To harness knowledge in applied Sciences and technology for the service of
humanity <hr />
</body>
</html>
HTML Exercise 4
<html>
<head>
<title> Tables </title>
</head>
<body>
<body bgColor = “#00ff00” TEXT = “#000000”>
<H1>MOUNT KENYA UNIVERSTITY</h1> <hr />
<font color=”#000000”>
<H3>REASONABLE FEES FOR OUR PROGRAMMES</h3>
25
<table border="1">
<tr>
<th>Course</th>
<th>Duration</th>
<th>Amount(Kshs)</th>
</tr>
<tr>
<td>Bachelor of Business Information Technology</td>
<td>4 Years</td>
<td>140,000</td>
</tr>
<tr>
<td>Bachelor of Business Management </td>
<td>4 Years</td>
<td>120,000</td>
</tr>
<tr>
<td>Bachelor of Commerce</td>
<td>4 Years</td>
<td>110,000</td>
</tr>
</table>
</body>
</html>
26
Question 1
a) Write the HTLM code that would be used to give the output below
Question 2
a) Write the html code that would be used to obtain the list of courses offered at MKU.
(8 Marks)
Question 3
(10 Marks)
27
[10 Marks]
Question 4
MT KENYA UNIVERSITY
Courses offered
i. BBIT
ii.DBIT
iii. DIT
Stages
Stage I
Stage II
Stage III
Stage IV
Stage V
iv. CIT
v. CBIT
vi. CICT
28