02 - Introduction to HTML
02 - Introduction to HTML
Content
• HTML
Editors
• Basic
HTML
HTML EDITORS
HTML Editors
• HTML
can
be
edited
by
using
a
professional
HTML
editor
like:
– Adobe
Dreamweaver
– Microsoft
Expression
Web
– CoffeeCup HTML
Editor
• However,
for
learning
HTML
a
text
editor
like
Notepad
(PC)
or
TextEdit (Mac) is
recommended
.
Write HTML Using Text Editor
Step
1:
Open
Notepad
• To
open
Notepad
in
Windows
7
or
earlier:
– Click
Start
(bottom
left
on
your
screen).
Click
All
Programs.
Click
Accessories.
Click
Notepad.
• To
open
Notepad
in
Windows
8
or
later:
– Open
the
Start
Screen
(the
window
symbol
at
the
bottom
left
on
your
screen).
Type
Notepad.
Write HTML Using Text Editor
Step
2:
Write
Some
HTML
• Write
or
copy
some
HTML
into
text
editor.
<html>
<head>
<title>Introduction
to
HTML</title>
</head>
<body>
My
First
HTML
page
</body>
</html>
Write HTML Using Text Editor
Step
3:
Save
the
HTML
Page
• Save
the
file
on
your
computer.
– Select
File
>
Save
as
in
the
Notepad
menu.
– Name
the
file
"[Link]"
or
any
other
name
ending
with
html.
– UTF-‐8
is
the
preferred
encoding
for
HTML
files.
– ANSI
encoding
covers
US
and
Western
European
characters
only.
Write HTML Using Text Editor
Write HTML Using Text Editor
Step
4:
View
HTML
Page
in
Your
Browser
• Open
the
saved
HTML
file
in
your
favorite
browser.
The
result
will
look
much
like
this:
Preparation for Tutorial
--- [Link]
--- [Link]
--- [Link]
A11CS0084 --- [Link]
--- [Link]
--- [Link]
audio
--- [Link]
--- [Link]
images
BASIC HTML
What is HTML?
• HTML
is
a
markup
language
for
describing
web
documents
(web
pages).
– HTML
stands
for
Hyper
Text
Markup
Language
– A
markup
language
is
a
set
of
markup
tags
– HTML
documents
are
described
by
HTML
tags
– Each
HTML
tag
describes
different
document
content
HTML Versions
• Since
the
early
days
of
the
web,
there
have
been
many
versions
of
HTML:
Version Year
HTML 1991
XHTML 2000
HTML5 2012
!
HTML Tags
• HTML
tags
are
keywords
(tag
names)
surrounded
by
angle
brackets:
– <tagname>content</tagname>
– HTML
tags
normally
come
in
pairs
like
<p>
and
</p>
– The
first
tag
in
a
pair
is
the
start
tag,
the
second
tag
is
the
end
tag
– The
end
tag
is
written
like
the
start
tag,
but
with
a
slash
before
the
tag
name
HTML Documents
HTML Example Activity
<html>
<head>
<title>Introduction
to
HTML</title>
</head>
<body>
My
First
HTML
page
</body>
</html>
Web Browsers
• The
purpose
of
a
web
browser
(Chrome,
IE,
Firefox,
Safari)
is
to
read
HTML
documents
and
display
them.
HTML ELEMENTS AND ATTRIBUTES
HTML Elements
• HTML
documents
are
made
up
by
HTML
elements.
• HTML
elements
are
written
with
a
start
tag,
with
an
end
tag,
with
the
content
in
between:
<tagname>content</tagname>
• The
HTML
element
is
everything
from
the
start
tag
to
the
end
tag:
<p>My
first
HTML
paragraph.</p>
HTML Attributes
• HTML
elements
can
have
attributes
• Attributes
provide
additional
information
about
an
element
• Attributes
are
always
specified
in
the
start
tag
• Attributes
come
in
name/value
pairs
like:
name="value"
HTML Elements and Attributes
Example
<html
lang="en-‐US">
<head>
<title>Introduction
to
HTML</title>
</head>
<body>
<h1>My
First
HTML
page</h1>
</body>
</html>
Basic HTML Elements
• Headings
• Paragraphs
• Images
• Tables
• List
• Links
• HTML
Styling
• HTML
Text
Formatting
Elements
HTML Headings
• Headings
are
defined
with
the
<h1>
to
<h6>
tags.
• <h1>
defines
the
most
important
heading.
<h6>
defines
the
least
important
heading.
• Use
HTML
headings
for
headings
only.
Don't
use
headings
to
make
text
BIG
or
bold.
• Search
engines
use
your
headings
to
index
the
structure
and
content
of
your
web
pages.
HTML Headings Example Activity
<html>
<head>
<title>Introduction
to
HTML</title>
</head>
<body>
<h1>This
is
heading
1</h1>
<h2>This
is
heading
2</h2>
<h3>This
is
heading
3</h3>
<h4>This
is
heading
4</h4>
<h5>This
is
heading
5</h5>
<h6>This
is
heading
6</h6>
</body>
</html>
HTML PARAGRAPHS
HTML Paragraphs
• HTML
documents
are
divided
into
paragraphs.
• The
HTML
<p>
element
defines
a
paragraph.
• Example
<p>This
is
a
paragraph</p>
<p>This
is
another
paragraph</p>
HTML Paragraphs Example Activity
<html>
<head>
<title>Introduction
to
HTML</title>
</head>
<body>
<p>This
is
a
paragraph</p>
<p>This
is
another
paragraph</p>
</body>
</html>
HTML Paragraphs Example Activity
<html>
<head>
<title>Introduction
to
HTML</title>
</head>
<body>
<p>
This
paragraph
contains
a
lot
of
lines
in
the
source
code,
but
the
browser
ignores
it.
</p>
<p>
This
paragraph
contains
a
lot
of
spaces
in
the
source
code,
but
the
browser
ignores
it.
</p>
</body>
</html>
HTML Line Breaks
• The
HTML
<br>
element
defines
a
line
break.
• The
<br>
element
is
an
empty
HTML
element.
It
has
no
end
tag.
• Use
<br>
if
you
want
a
line
break
(a
new
line)
without
starting
a
new
paragraph:
<p>This
is<br>a
para<br>graph
with
line
breaks</p>
HTML Line Breaks Example Activity
<html>
<head>
<title>Introduction
to
HTML</title>
</head>
<body>
<p>This
is<br>a
para<br>graph
with
line
breaks</p>
</body>
</html>
The HTML <pre> Element
• The
HTML
<pre>
element
defines
a
block
of
pre-‐formatted
text,
with
structured
spaces
and
lines.
• To
display
anything,
with
right
spacing
and
line-‐breaks,
you
must
wrap
the
text
in
a
<pre>
element:
The HTML <pre> Element Activity
Example
<html>
<head>
<title>Introduction
to
HTML</title>
</head>
<body>
<p>The
pre
tag
is
needed
for
displaying
lyrics
or
poems:</p>
<pre>
Because
you
know
I'm
all
about
that
bass
'Bout
that
bass,
no
treble
I'm
all
about
that
bass
'Bout
that
bass,
no
treble
I'm
all
about
that
bass
'Bout
that
bass,
no
treble
I'm
all
about
that
bass
'Bout
that
bass
</pre>
</body>
</html>
HTML LISTS
HTML Lists
• HTML
can
have
Unordered
Lists,
Ordered
Lists,
or
Description
Lists:
Square None
<ul type="square"> <ul type="none">
<li>Coffee</li> <li>Coffee</li>
<li>Tea</li> <li>Tea</li>
<li>Milk</li> <li>Milk</li>
</ul> </ul>
Ordered HTML Lists Activity
<html>
<head>
<title>Introduction
to
HTML</title>
</head>
<body>
<h1>HTML
Tables
Tutorials</h1>
<h2>Basic
HTML
Tables
(Without
setting
the
width)</h2>
<table>
<tr>
<td>Jill</td><td>Smith</td>
<td>50</td></tr>
<tr>
<td>Eve</td><td>Jackson</td>
<td>94</td></tr>
</table>
<body>
</html>
HTML Tables with Width Activity
Attribute
<html>
<head>
<title>Introduction
to
HTML</title>
</head>
<body>
<h1>HTML
Tables
Tutorials</h1>
<h2>Basic
HTML
Tables
(Without
setting
the
width)</h2>
<table
width="100%">
<tr>
<td>Jill</td><td>Smith</td>
<td>50</td></tr>
<tr>
<td>Eve</td><td>Jackson</td>
<td>94</td></tr>
</table>
<body>
</html>
An HTML Table with a Border Activity
Attribute
<h2>An
HTML
Table
with
a
Border
Attribute</h2>
<table
border="1"
width="100%">
<tr><td>Jill</td><td>Smith</td><td>50</td><tr>
<tr><td>Eve</td><td>Jackson</td><td>94<td></tr>
</table>
HTML Table with Cell Padding
• Cell
padding
specifies
the
space
between
the
cell
content
and
its
borders.
• If
you
do
not
specify
a
padding,
the
table
cells
will
be
displayed
without
padding.
HTML Table with Cell Padding Activity
</table>
HTML Table with Cell Spacing
• CELLSPACING
controls
the
space
between
table
cells.
• If
you
do
not
specify
a
padding,
the
table
cells
will
be
displayed
without
spacing.
• Although
there
is
no
official
default,
browsers
usually
use
a
default
of
2.
HTML Table with Cell Spacing Activity
</table>
HTML Table Headings
• Table
headings
are
defined
with
the
<th>
tag.
• By
default,
all
major
browsers
display
table
headings
as
bold
and
centered.
HTML Table Headings 1 Activity
Columns
<h2>Table
Cells
that
Span
Many
Columns</h2>
<table
border="1">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Bill
Gates</td>
<td>555
77
854</td>
<td>555
77
855</td>
</tr>
</table>
Table Cells that Span Many Rows
• To
make
a
cell
span
more
than
one
row,
use
the
rowspan attribute:
Table Cells that Span Many Activity
Rows
<h2>Table
Cells
that
Span
Many
Rows</h2>
<table
border="1">
<tr>
<th>Name:</th>
<td>Bill
Gates</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>555
77
854</td>
</tr>
<tr>
<td>555
77
855</td>
</tr>
</table>
More Complex table
• Can
you
do
it?
HTML LINKS
HTML Links - Hyperlinks
• HTML
links
are
hyperlinks.
• A
hyperlink
is
an
element,
a
text,
or
an
image
that
you
can
click
on,
and
jump
to
another
document.
• In
HTML,
links
are
defined
with
the
<a>
tag.
• Link
Syntax:
<a
href="url">link
text</a>
HTML Links – Hyperlinks Activity
Example
<html>
<head>
<title>Introduction
to
HTML</title>
</head>
<body>
<h1>HTML
Links
-‐ Hyperlinks
Tutorials</h1>
<h2>HTML
Global
Link
Examples</h2>
<a
href="[Link]
to
UTM
Website</a>
</body>
</html>
Local Links
• The
previous
example
used
an
absolute URL
(A
full
web
address).
• A
local
link
(link
to
the
same
web
site)
is
specified
with
a
relative URL
(without
[Link]
HTML Links – Local Links Activity
!
HTML Links - The target Activity
Attribute Example
<h2>HTML
Links
-‐ The
target
Attribute
Examples</h2>
<ul>
<li><a
href="[Link]
target="_blank">Visit
Uncle
Google!</a></li>
<li><a
href="[Link]"
target="_self">HTML
Headings</a></li>
<li><a
href="[Link]"
target="_parent">HTML
Paragraphs</a></li>
<li><a
href="[Link]"
target="_top">HTML
Lists</a></li>
</ul>
HTML Links - Image as Link
• It
is
common
to
use
images
as
links:
• Example
<a
href=”[Link]”><img src=”[Link]"
alt=”Main
Page"
style="width:42px;height:42px;border:0”></a>
HTML Links - Image as Link Activity
Value Description
color_name Specifies the background color with a color name (like "red")
hex_number Specifies the background color with a hex code (like "#ff0000")
!
HTML <body> bgcolor Activity
Attribute
<html>
<head>
<title>Introduction
to
HTML</title>
</head>
<body
bgcolor="#E6E6FA">
<h1>HTML
Styling</h1>
</body>
</html>
HTML <body> bgcolor Attribute
<html>
<head>
<title>Introduction
to
HTML</title>
</head>
<body
bgcolor="#E6E6FA"
background="[Link]">>
<h1>HTML
Styling</h1>
</body>
</html>
HTML <font> color Attribute
• The
color property
defines
the
font
color
to
be
used
for
an
HTML
element:
• Syntax:
<font
color="color_name|hex_number|rgb_number">
<h2>HTML
<font>
color
Attribute</h2>
<font
color="red"><h3>This
is
a
heading</h3></font>
<font
color="green"><p>This
is
a
paragraph.</p></font>
HTML <font> face Attribute
• The
face property
defines
the
font
to
be
used
for
an
HTML
element:
• Syntax:
<font
face="font_family">
<h2>HTML
<font>
face
Attribute</h2>
<font
face="verdana"><h3>This
is
a
heading</h3></font>
<font
face="courier"><p>This
is
a
paragraph.</p></font>
HTML Text Alignment Attribute
• The
align property
defines
the
font
to
be
used
for
an
HTML
element:
• Syntax:
<font
align="left|right|center|justify">
<h2>HTML
Text
Alignment
Attribute</h2>
<font
align="center"><h3>This
is
a
heading</h3></font>
<font
align="right"><p>This
is
a
paragraph.</p></font>
HTML Text Attribute All Together
• The
HTML
text
attribute
property
can
be
put
all
together.
<h2>HTML
Text
Alignment
Attribute
All
Together</h2>
<font
face="verdana"
align="left"
color="red"><h3>This
is
a
heading</h3></font>
<font
face=”arial"
align="center"
color="green"><p>This
is
a
paragraph.</p></font>
HTML TEXT FORMATTING ELEMENTS
HTML Formatting Elements
• HTML
also
defines
special
elements,
for
defining
text
with
a
special
meaning.
• HTML
uses
elements
like
<b>
and
<i>
for
formatting
output,
like
bold
or
italic
text.
• Formatting
elements
were
designed
to
display
special
types
of
text:
– Bold
text
– Important
text
– Italic
text
– Emphasized
text
– Marked
text
– Small
text
– Deleted
text
– Inserted
text
– Subscripts
– Superscripts
HTML Bold and Strong Formatting Activity
Formatting
• The
HTML
<i>
element
defines
italic
text,
without
any
extra
importance.
• The
HTML
<em>
element
defines
emphasized
text,
with
added
semantic
importance.
• Example
<h2>HTML
Italic
and
Emphasized
Formatting</h2>
<p>This
text
is
normal.</p>
<p><i>This
text
is
italic</i>.</p>
<p><em>This
text
is
emphasized</em>.</p>
HTML Small Formatting Activity
• text
• checkbox
• radio (buttons)
• select (options)
• textarea
• password
• button
• submit
• reset
• hidden
• file
• image
The method and action attributes
• The method attribute specifies the way that form data is sent to the server
program
– GET appends the data to the URL
– POST sends the data separately
• The action attribute specifies a server program (e.g. a php program .php
extension) that processes the form data
• Can also send an email: action=“[Link]
<body>
<form method="POST" action="[Link]">
<h2>Tell us what you think</h2>
<!-- etc -->
</form>
</body>
The input element: type="text"
• type="submit"
– clicking this button sends the form data
to the program (URL) specified in the
action attribute of the form
• type="reset"
– clicking this button clears all data
entered so far
Thank you<br>
<input type="submit" name="send" value="Send">
<input type="reset" name="clear" value="Clear"><br>
The input element:
type="password/file/hidden"
• type="password"
– similar to type="text" except that the input is
echoed with asterisks (so not visible)
• type="file"
– provides a file dialogue box to specify a file that
is sent to the server
• type="hidden"
– similar to text input, but the value attribute is
used to specify data that is to be sent to the
server. Nothing appears on the screen.
– The data might be set by a server program to
keep track of the details of a particular
transaction.
The textarea element