Lecture 2- Introduction to HTML
Lecture 2- Introduction to HTML
BSE 1208
Introduction to Web
Development
Lesson objectives
Upon completion of this chapter, the student should be able
to:
Define HTML
Have a clear understanding of tags
Be a able to create a simple HTML document and save it.
Be able to format an HTML document
What is HTML?
HTML is the standard markup language for Web
pages.
The first tag in a pair is the start tag, the second tag is the end tag
Start and end tags are also called opening tags and closing tags
HTML Documents = Web Pages
HTML documents describe web pages
<head>: tells the Web browser that this is the beginning of header for the
page
<title>: tells the Web browser that this is the beginning of the title of the
page
<body>: tells the Web browser that this is the beginning of the Web page
content (body)-- everything you want to say and see on your page will
follow this tag
HEAD TAGS
Every HTML document needs a pair of HEAD tags. The
<head> element is a container for metadata (data about data)
and is placed between the <html> tag and the <body> tag.
Metadata is data about the HTML document.
Metadata is not displayed.
Metadata typically define the document title,
character set, styles, scripts, and other meta
information.
The following elements can go inside the <head>
element:
<title> (required in every HTML document)
<style>
<base>
<link>
<meta>
HEAD TAGS
<HTML>
<HEAD>
</HEAD>
</HTML>
HEAD TAGS: The <base> tag
The <base> tag (specifies a default URL and target
for all links on a page) goes inside <head>:
<html>
<head>
<base href="https://www.w3schools.com/"
target="_blank">
</head>
<body>
</body>
</html>
HEAD TAGS: The <style> tag
The <style> tag (adds style information to a page)
goes inside <head>:
<html>
<head>
<style>
h1 {color:red;}
p {color:blue;}
</style>
</head>
<body>
<h1>A heading</h1>
<p>A paragraph.</p>
</body>
</html>
HEAD TAGS: The <link> tag
The <link> tag (links to an external style sheet)
goes inside <head>:
<html>
<head>
<link rel="stylesheet" type="text/css"
href="styles.css">
</head>
<body>
</body>
</html>
TITLE TAGS
The <title> tag defines the title of the
document. The title must be text-only, and it
is shown in the browser's title bar or in the
page's tab.
<HTML>
<HEAD>
<TITLE>
</TITLE>
</HEAD>
</HTML>
THE BODY TAG
The bulk of the page goes in the BODY tags.
<HTML>
<HEAD>
<TITLE>
</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>
Place text in the body
<HTML>
<HEAD>
<TITLE>My first webpage!</TITLE>
</HEAD>
<BODY> Hello Everyone! Today is great </BODY>
</HTML>
Saving HTML document
o When your in Notepad, click file then save as.
Note:
What you made is a skeleton HTML document. This is the
minimum required information for a web document and all
web documents should contain these basic components.
The lowest value that can be given to one of the light sources is 0
(in HEX: 00). The highest value is 255 (in HEX: FF).
Once the entire page 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.
We can however adjust the dimensions until the image appears
the way we want it on the web page.
Attributes
Align, face, color, size.
What we are (more or less) telling the browser is: at the <b> start
making things bold, and at the </b> stop making things bold.
Making things italic
To make thing italic ,use the<i> tag.
<html>
<head><title></title>
</head>
<body>Something <i>very</i> <b>good</b>
</body>
</html>
Underlining text
Use the <u> tag.
<html>
<head><title></title>
</head
<body><u>Something</u> <i>very</i> <b>good</b>
</body>
</html>
Using a combination of tags
<html>
<head><title></title>
</head>
<body>Something really <i><b>cool</b></i>
</body>
</html>
Nested tags
The above is an example of nested tags.
<i><b></b></i>
Nested tags.... good
Changing font size
First add the <FONT> tags...
<body>Something really <font>good</font></body>
Every browser has a default font setting - font name, size and color.
Unless you have messed with it the default is probably Times New
Roman 12pt (which translates into 3 for our purposes) and it's black.
But we can specify font names other than the defaults. Like ARIAL
and COMIC SANS.
<FONT SIZE=6> …
Font
<BODY>Something really <FONT
FACE="ARIAL">good</FONT></BODY>
The font will only display if your viewer has that font installed
on their computer. Otherwise, they will only see the default
font
The browser looks for ARIAL. If it finds it, it uses it. If not, it
goes on to HELVETICA. If it can't find that, it looks for
LUCIDA SANS. And if it can't find that it uses the default
font.
Using more than one attribute in Font tag.
<html>
<head><title></title></head>
<body>Something really <font color="#ff0000"
face=“arial" size="7">good</font>
</body>
</html>
headings
Headings range from 1-6.
<h1>Something really cool<h1>
<h2>Something really cool<h2>
<h3>Something really cool<h3>
<h4>Something really cool<h4>
<h5>Something really cool<h5>
<h6>Something really cool<h6>
Align attribute
A useful heading attribute is ALIGN.
Anchor
Document 1 Link
(reference) Destinatio
n
Here is a link to
document 2
Document 2
This is document 2.
Hypertext Links
Hypertext is the essence of the Web!
Example
This is an unordered list
• something red
• something blue
• something old
• something new
Add a list item
<body>
Today’s shopping list
<ul>
<li> Matooke</li>
<li> Sugar</li>
<li>Salt</li>
<li>Meat</li>
<li>Charcoal</li>
</ul>
</body>
Ordered list
<body>
What I want on my birthday
<ol>
<li>a big red truck </li>
<li>a real fast speedboat </li>
<li>a drum set </li>
<li>a BB gun </li>
<li>a Melanie Griffith </li>
</ol></body>
Horizontal rule
The <hr> tag in HTML stands for horizontal rule and is used
to insert a horizontal rule or a thematic break in an
HTML page to divide or separate document sections.
The <hr> tag is an empty tag, and it does not require an end
tag
<body>
<hr width=20%>
<hr width=50%>
<hr width=100%>
<hr width=20>
<hr width=50>
<hr width=100>
</body>
The <br> Tag
<html><head><title></title></head>
<body>
<table border=3>
<tr>
<td>Bricks, sand and water</td>
</tr></table>
</body>
</html>
Table width
<html><head><title></title></head>
<body>
<table border=“3” width=“50”>
<tr>
<td>Bricks</td>
</tr>
</table></body>
</html>
Working with table height
<html><head><title></title></head>
<body>
<table border=“3” width=“100” height=“75”>
<tr>
<td>Bricks</td>
</tr>
</table>
</body>
</html>
Aligning cell data
Use is be made of the align attribute.
<table border=“3” width=“100” height=“75”>
<tr>
<td align="center">Bricks</td>
<td align="right"> Sand </td>
<td align="left"> Water </td>
</tr>
</table>
Default value
The default value is (usually) align="left".
It's often a fine idea to specify how big each cell is.
<html><head>
<title> Introduction to forms</title>
</head><body>
<form></form>
</body>
<html>
The <input> Element
The HTML <input> element is the most
used form element.
An <input> element can be displayed in
many ways, depending on the type
attribute.
The <input> Element
Text Fields
<form>
<label for="fname">First
name:</label><br>
<input type="text" id="fname"
name="fname"><br>
<label for="lname">Last
name:</label><br>
<input type="text" id="lname"
name="lname">
</form>
The <label> Element
The <label> tag defines a label for many
form elements.
The <label> element is useful for screen-
reader users, because the screen-reader will
read out loud the label when the user focuses
on the input element.
The for attribute of the <label> tag should be
equal to the id attribute of the <input>
element to bind them together.
The Name Attribute for <input>
Each input field must have a name attribute
to be submitted.
If the name attribute is omitted, the value of
the input field will not be sent at all.
The Action Attribute
The action attribute defines the action to be
performed when the form is submitted.
Usually, the form data is sent to a file on the
server when the user clicks on the submit
button.
In the example on next slide, the form data is
sent to a file called “bse.php". This file
contains a server-side script that handles the
form data:
If the action attribute is omitted, the action
is set to the current page.
The Action Attribute ..
<form action="/bse.php">
<label for="fname">First
name:</label><br>
<input type="text" id="fname"
name="fname" value=“Lilian"><br>
<label for="lname">Last
name:</label><br>
<input type="text" id="lname"
name="lname" value=“vanessa"><br><br>
<input type="submit" value="Submit">
</form>
The Target Attribute: <form
action="/action_page.php" target="_blank">
<FORM>
<INPUT TYPE="text"
NAME="ADDRESS" VALUE=”Makerere">
</FORM>
Adding SIZE
<FORM>
<INPUT TYPE="text" NAME="ADDRESS" VALUE="
Makerere " SIZE=10>
<INPUT TYPE="text" NAME="ADDRESS" VALUE="
Makerere " SIZE=20>
<INPUT TYPE="text" NAME="ADDRESS" VALUE="
Makerere " SIZE=30>
</FORM>
Password fields
Very similar to the TYPE=TEXT is the
TYPE=PASSWORD.
<FORM><INPUT TYPE="password"></FORM>
Remember that each <INPUT> must have a NAME.
<FORM><INPUT TYPE="password"
NAME="USERPASS"></FORM>
Radio buttons
<FORM>
<INPUT TYPE="radio" NAME="BEST FRIEND">
<INPUT TYPE="radio" NAME="BEST FRIEND">
<INPUT TYPE="radio" NAME="BEST FRIEND">
</FORM>