Lecture 02 HTML Basics
Lecture 02 HTML Basics
Outline
Introduction
Markup Languages
Editing HTML
Common Tags
Headers
Text Styling
Linking
Images
Formatting Text With <FONT>
Special Characters, Horizontal Rules and More Line Breaks
1 Introduction
HTML
Markup Languages
Markup language
HTML
HTML tags
HTML files
Errors in HTML
Common Tags
Always include the <HTML></HTML> tags
Comments placed inside <!----!> tags
HTML documents
HEAD section
BODY section
Page content
Includes text, images, links, forms, etc.
Elements include backgrounds, link colors and font faces
P element forms a paragraph, blank line before and after
Headers
Headers
CENTER element
Headers
<html>
<head>
<title>Internet and WWW How to Program - Headers</title>
</head>
<body>
<h1>Level 1 Header</h1>
<h2>Level 2 header</h2>
<h3>Level 3 header</h3>
<h4>Level 4 header</h4>
<h5>Level 5 header</h5>
<h6>Level 6 header</h6>
</body>
</html>
Text Styling
Underline style
<U></U>
opened
Emphasis (italics) style
<EM></EM>
<STRONG></STRONG>
1 <HTML>
2
3 <!-- Fig. 3.3: main.html -->
4 <!-- Stylizing your text -->
5
6 <HEAD>
7 <TITLE>Internet and WWW How to Program - Welcome</TITLE>
8 </HEAD>
9
10<BODY>
11<H1 ALIGN = "center"><U>Welcome to Our Web Site!</U></H1>
12
13<P>We have designed this site to teach
14about the wonders of <EM>HTML</EM>. We have been using
15<EM>HTML</EM> since <U>version<STRONG> 2.0</STRONG></U>,
16and we enjoy the features that have been added recently.
17seems only a short time ago that we read our first
It
18book. Soon you will know about many of the great new
<EM>HTML</EM>
19of HTML 4.0.</P>
features
20
21<H2 ALIGN = "center">Have Fun With the Site!</H2>
22
23</BODY>
24</HTML>
Description
<b>
<em>
<i>
<small>
<strong>
<sub>
<sup>
<ins>
<del>
<mark>
Linking
Links inserted using the A (anchor) element
Linking
A hyperlink (or link) is a word, group of words, or
<html>
<head>
<title>Internet and WWW How to Program - Links</title>
</head>
<body>
<h1>Here are my favorite sites</h1>
<p><strong>Click a name to go to that page.</strong></p>
<!-- Create four text hyperlinks -->
<p><a href = "http://www.deitel.com">Deitel</a></p>
<p><a href = "http://www.prenhall.com">Prentice Hall</a></p>
<p><a href = "http://www.yahoo.com">Yahoo!</a></p>
<p><a href = "http://www.usatoday.com">USA Today</a></p>
</body>
</html>
<html>
<head>
<title>Hyper Linking </title>
</head>
<body>
<p>My email address is
<a href = "mailto:lokesh.sharma@jaipur.manipal.edu">
lokesh.sharma@jaipur.manipal.edu
</a>
. Click the address and your browser will
open an e-mail message and address it to me.
</p>
</body>
</html>
HTML/XHTML documents.
The <title> element:
defines a title in the browser toolbar
provides a title for the page when it is added to favourites
displays a title for the page in search-engine results
Images
Images as anchors
Background color
Images
Image background
<BODY BACKGROUND = background>
Image does not need to be large as browser tiles image across and down the
screen
Pixel
Stands for picture element
Each pixel represents one addressable dot of color on the screen
Insert image into page
Use <IMG> tag
Attributes:
SRC = location
HEIGHT (in pixels)
WIDTH (in pixels)
BORDER (black by default)
ALT (text description for browsers that have images turned off or cannot view
images)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<HTML>
<!-- Fig. 3.6: picture.html -->
<!-- Adding images with HTML -->
<HEAD>
<TITLE>Internet and WWW How to Program - Welcome</TITLE>
</HEAD>
<BODY BACKGROUND = "background.gif">
<CENTER>
<!-- Format for entering images: <IMG SRC = "name"> -->
<IMG SRC = "deitel.gif" BORDER = "1" HEIGHT = "144"
WIDTH = "200" ALT = "Harvey and Paul Deitel">
</CENTER>
</BODY>
</HTML>
<html>
<head>
<title>Internet and WWW How to Program - Navigation Bar </title>
</head>
<body>
<p>
<a href = "links.html"><img src = "buttons/links.jpg" width = "65"
height = "50" alt = "Links Page" />
</a><br />
<a href = "list.html"><img src = "buttons/list.jpg" width = "65"
height = "50" alt = "List Example Page" />
</a><br />
<a href = "contact.html"><img src = "buttons/contact.jpg" width = "65"
height = "50" alt = "Contact Page" />
</a><br />
COLOR
Preset or hex color code
Value in quotation marks
Note: you can set font color for whole document using TEXT
attribute in BODY element
SIZE
To make text larger, set SIZE = +x
To make text smaller, set SIZE = -x
x is the number of font point sizes
FACE
Font of the text you are formatting
Be careful to use common fonts like Times, Arial, Courier and
Helvetica
Browser will display default if unable to display specified font
Example
<FONT COLOR = red SIZE = +1 FACE = Arial>
</FONT>
1<HTML>
2
3<!-- Fig. 3.8: main.html
-->
4<!-- Formatting text size and color -->
5
6<HEAD>
7<TITLE>Internet and WWW How to Program - Welcome</TITLE>
8</HEAD>
9
10<BODY>
11
12<H1 ALIGN = "center"><U>Welcome to Our Web Site!</U></H1>
13
14<!-- Font tags change the formatting of text they enclose -->
15<P><FONT COLOR = "red" SIZE = "+1" FACE = "Arial">We have
16designed this site to teach about the wonders of
17<EM>HTML</EM>.</FONT>
18
19<FONT COLOR = "purple" SIZE = "+2" FACE = "Verdana">We have been
20using <EM>HTML</EM> since <U>version<STRONG> 2.0</STRONG></U>,
21and we enjoy the features that have been added recently.</FONT>
22
23<FONT COLOR = "blue" SIZE = "+1" FACE = "Helvetica">It
24seems only a short time ago that we read our first <EM>HTML</EM>
25book.</FONT>
26
27<FONT COLOR = "green" SIZE = "+2" FACE = "Times">Soon you will
28know about many of the great new feature of HTML 4.0.</FONT></P>
29
30<H2 ALIGN = "center">Have Fun With the Site!</H2></P>
31
32</BODY>
33</HTML>
Ex. &
Insert an ampersand
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<HTML>
<!-- Fig. 3.9: contact.html
-->
<!-- Inserting special characters -->
<HEAD>
<TITLE>Internet and WWW How to Program - Contact Page</TITLE>
</HEAD>
<BODY>
<!-- Special characters are entered using the form &code; -->
<P>My email address is <A HREF = "mailto:deitel@deitel.com">
deitel@deitel.com</A>. Click on the address and your browser
will automatically open an email message and address it to my
address.</P>
<P>All information on this site is <STRONG>©</STRONG>
Deitel <STRONG>&</STRONG> Associates, 1999.</P>
<!-- Text can be struck out with a set of <DEL>...</DEL>
-->
<!-- tags, it can be set in subscript with <SUB>...</SUB>, -->
<!-- and it can be set into superscript with <SUP...</SUP> -->
<DEL><P>You may copy up to 3.14 x 10<SUP>2</SUP> characters
worth of information from this site.</DEL><BR> Just make sure
you <SUB>do not copy more information</SUB> than is allowable.
<P>No permission is needed if you only need to use <STRONG>
< ¼</STRONG> of the information presented here.</P>
</BODY>
</HTML>
WIDTH
Adjusts the width of the rule
Either a number (in pixels) or a percentage
SIZE
Determines the height of the horizontal rule
In pixels
ALIGN
Either left, right or center
NOSHADE
Eliminates default shading effect and displays horizontal rule as a solidcolor bar
1<HTML>
2
3<!-- Fig. 3.10: header.html
-->
4<!-- Line breaks and horizontal rules -->
5
6<HEAD>
7<TITLE>Internet and WWW How to Program - Horizontal
Rule</TITLE>
8</HEAD>
9
10<BODY>
11<!-- Horizontal rules as inserted using the format: -->
12<!-- <HR WIDTH = ".." SIZE = ".." ALIGN = "..">
-->
13<HR WIDTH = "25%" SIZE = 1>
14<HR WIDTH = "25%" SIZE = 2>
15<HR WIDTH = "25%" SIZE = 3>
16
17<P ALIGN = "left"><STRONG>Size:</STRONG>4
18<STRONG>Width:</STRONG>75%
19<HR WIDTH = "75%" SIZE = "4" ALIGN = "left">
20
21<P ALIGN = "right"><STRONG>Size:</STRONG>12
22<STRONG>Width:</STRONG>25%
23<HR WIDTH = "25%" SIZE = "12" ALIGN = "right">
24
25<P ALIGN = "center"><STRONG>Size:</STRONG>8
26<STRONG>Width:</STRONG>50%
27<STRONG><EM>No shade...</EM></STRONG>
28<HR NOSHADE WIDTH = "50%" SIZE = "8" ALIGN = "center">
29
30</BODY>
31</HTML>