CH 2
CH 2
CH 2
Chapter Two
HTML AND ITS BASICS
Lecture I
By Tesfahun N.
What is
What is HTML
HTML Files
A web site will often contain many html files that link to each
other.
4
HTML Tags
HTML tags are the hidden keywords within a web page
that define how your web browser must format and
display the content
an opening <html>
<body>
8
HTML Code Formatting
The HTML source code should be formatted to
sacrificed
9
First HTML Page
test.html
<!DOCTYPE html>
<html>
<head>
< t i t l e > w e l l came t o WP</title>
</head>
<body>
<h1>My F i r s t Heading</h1>
<p>My f i r s t paragraph.</p>
</body>
</html> 10
The <!DOCTYPE> Declaration
HTML documents must start with a document type definition (DTD)
• It informs the web browser about the type and version of HTML
HTML 4.01, XHTML 1.0 XHTML 1.1, HTML 5
• it helps the browser to handle and load it properly.
• Example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
11
Cont..
The <html> root element of an HTML page
• Image Tags
<img src="logo.gif" / >
<body>
<a href="https://www.youtube.com/" t i t l e =
“youtube site">This i s a l i n k . < / a >
<br / >
<img src="logo.gif" / >
<br / >
<strong>Bold</st r ong> and <em>i t a l i c</em> te xt .
14
HTML Attributes
All HTML elements can have attributes
• Example
• <a href="https://www.w3schools.com">Visit
W3Schools</a>
The src Attribute
The <img> tag is used to embed an image in an
HTML page.
The src attribute specifies the path to the image to be
displayed:
• Example
• <img src="img_girl.jpg">
The alt Attribute
The required alt attribute for the <img> tag
specifies an alternate text for an image, if the
image for some reason cannot be displayed
• Example
19
The width and height Attributes
• Example
• <img src="img_girl.jpg" width="500" height="600">
The style Attribute
• Example
• <p style="color:red;">This is a red paragraph.</p>
The lang Attribute
You should always include the lang attribute inside
the <html> tag, to declare the language of the Web
page. This is meant to assist search engines and
browsers.
<!DOCTYPE html>
<html lang="en">
<body>
...
</body>
</html>
Headings and Paragraphs
<h1>Heading 1</h1>
<h2>Sub heading 2</h2>
<h3>Sub heading 3</h3>
Paragraph Tags
<p>This i s my f i r s t paragraph</p>
<p>This i s my second paragraph</p>
<meta>
<script>
<link>
<style>
25
Header
HTML header
<!DOCTYPE HTML>
<html>
<head>
<title>My F i r s t HTML Page</title>
</head>
<body>
<p>This i s some t e x t . . . < / p >
</body>
</html>
26
<head> Section: <title> tag
Title should be placed between <head> and </head> tags
<head>
<title>here i s the t i t l e section
</title>
</head>
27
<head> Section: <meta>
Meta tags additionally describe the content contained
within the page
28
<head> Section: <script>
The <script> element is used to embed scripts into an HTML
document
VBScript
29
The <script> Tag – Example
The <script> tag is used to embed a client-side script
(JavaScript). scripts-example.html
<!DOCTYPE HTML>
<html>
<head>
<title>JavaScript Example</title>
<script type="text/javascript">
function sayHello() {
document.write("<p>Hello World!<\/p>");
}
</script>
</head>
<body>
<script type=
"te x t/ ja vascr ip t " >
sayHello();
</script>
</body>
</html>
30
<head> Section: <style>
The <style> element embeds formatting
information (CSS styles) into an HTML page
style-example.html
<html>
<head>
<style type="text/css">
p { f on t- s iz e : 12pt; line -h eight : 12pt; }
p : f i r s t - l e t t e r { f o nt- s iz e : 200%; }
span { text-transform: uppercase; }
</style>
</head>
<body>
<p>Styles demo.<br / >
<span>Test uppercase</span>.
</p>
</body>
</html>
31
<body> Section:Introduction
The <body> section describes the viewable
portion of the page
Starts after the <head> </head> section
Begins with <body> and ends with </body>
<html>
<head><title>Test page</title></head>
<body>
< ! - - This i s the Web page body - - >
</body>
</html>
32
Comments: <!-- --> Tag
Comments can exist anywhere between the <html></html> tags
33
Text Formatting
Text formatting tags modify the text between the opening tag and the closing tag
• Ex. <b>Hello</b> makes “Hello” bold
<b></b> bold
<i></i> italicized
<u></u> underlined
<sup></sup> Samplesuperscript
<sub></sub> Samplesubscript
<strong></strong> strong
<em></em> emphasized
<a href="stuff/cat.html">Catalog</a>
35
Hyperlinks: <a> Tag (2)
Link to an external Web site:
Always use a full URL, including "http://",
not just www.somesite.com
<a href= "h t tp : / /www.devbg .org"
target="_blank">BASD</a>
Link to an e-mail address:
<a href="mailto:bugs@example.com?subject=Bug+Report">
Please report bugs here (by e-mail only)</a>
36
Hyperlinks and Sections
Link to another location in the same document:
<a href="#section1">Go to Introduction</a>
...
<h2 id="section1">Introduction</h2>
<a href="chapter3.html#section3.1.1">Go to
Section 3.1.1</a>
<!–- I n chapter3.html - - >
...
<div id="section3.1.1">
<h3>3.1.1. Technical Background</h3>
</div>
37
Hyperlinks – Example
hyperlinks.html
<br / >
links-to-same-document.html
<h1>Table of Contents</h1>
<p><a href="#section1">Introduction</a><br />
<a href="#section2">Some background</A><br />
<a href="#section2.1">Project History</a><br />
. . . t h e rest of the table of contents...
< ! - - The document text follows here -- >
<h2 id="section1">Introduction</h2>
. . . Section 1 follows here . . .
<h2 id="section2">Some background</h2>
. . . Section 2 follows here . . .
<h3 id="section2.1">Project History</h3>
. . . Section 2.1 follows here . . .
39
Miscellaneous Tags
<hr/>: Draws a horizontal rule (line):
<center></center>: Deprecated!
<center>Hello World!</center>
<font></font>: Deprecated!
<font size="3" color="blue">Font3</font>
<font size="+4" color="blue">Font+4</font>
40
Miscellaneous Tags – Example
misc.html
<html>
<head>
<title>Miscellaneous Tags Example</title>
</head>
<body>
<hr size="5" width="70%" / >
<center>Hello World!</center>
<font size="3" color="blue">Font3</font>
</body>
</html>
41
Ordered Lists: <ol> Tag
Create an Ordered List using <ol></ol>:
<ol type="1">
<li>Apple</li>
<li>Orange</li>
<li>Gr apefr uit< /l i>
</ol>
43
Unordered Lists: <ul> Tag
Create an Unordered List using <ul></ul>:
<ul type="disk">
<li>Apple</li >
<li>Orange</li>
<li>Gr apefr uit</ l i>
</ul>
44
Definition lists: <dl> tag
Create definition lists using <dl>
Definition is indented
45
Lists – Example
<ol type="1"> lists.html
<li>Apple</li>
<li>Orange</li>
<l i> Gr ap e fr u it</l i>
</ol>
<ul type="disc">
<li>Apple</li>
<li>Orange</li>
<l i> Gr ap e fr u it</l i>
</ul>
<dl>
<dt>HTML</dt>
<dd>A markup lang…</dd>
</dl>
46
HTML Special Characters
Symbol Name HTML Entity Symbol
Copyright Sign © ©
Registered Trademark Sign ® ®
Trademark Sign ™ ™
Less Than < <
Greater Than > >
Ampersand & &
Non-breaking Space
Em Dash — —
Quotation Mark " "
Euro € €
British Pound £ 47 £
Japanese Yen ¥ ¥
Block and Inline Elements
Block elements add a line break before and after them
Example:
div.html
49
The <span> Tag
Inline style element
in the document
s p a n .h tm l
Very u s e f u l withCSS
<p>This one i s <span style="color:red; f o n t -
weight:bold">only a test</span>.</p>
<p>This onei s another <span style="font-
size:32px; font-weight:bold">TEST</span>.</p>
50
Cont..
HTML Tables (2)
Tables represent tabular data
A table consists of one or several rows
Each row has one or more columns
56
Column and Row Span
• Table cells have two important attributes:
Colspan rowspan
colspan="1" colspan="1" rowspan="1"
rowspan="2"
Example:
The “method" attribute tells how the form data
should be sent – via GET or POST request
Radio buttons:
<input type="radio" name="title"
value="Mr." / >
Radio buttons can be grouped, allowing only
one to be selected from a group:
<input type="radio" name="city" value="Lom" / >
<input type="radio" name="c i t y " value="Ruse" / >
60
Other Form Controls
Dropdown menus:
<select name=“department">
<option value="Value 1"
sele cted="se lected">cs</opt i o n>
<option value="Value 2">IS</option>
<option value="Value 3">IT</option>
</select>
Submit button:
61
Other Form Controls (2)
Reset button – brings the form to its initial state
<input t ype="reset " name="r esetBtn"
value="Reset the form" / >
Image button – acts like submit but image is
displayed and click coordinates are sent
<input type="image" sr c="submi t . gi f "
name="submitBtn" alt="Submit" / >
62
Other Form Controls (3)
Password input – a text field which masks the entered
text with * signs
<input type="password" name="pass" / >
63
Other Form Controls (4)
File input – a field used for uploading files
<input type="file" name="photo" / >
Form labels are used to associate an explanatory
text to a form field using the field's ID.
<label for="fn">First Name</label>
<input type="text" id="fn" / >
64
form.html
HTML Forms – Example
<form method="post" action="apply-now.php">
<input name="subject" type="hidden" value="Class" / >
<fieldse t style="width:150px"><legend>Academic information</legend>
<label for="degree">Degree</label>
<select name="degree" id="degree">
<option value="BA">Bachelor of Art</option>
<option value="BS">Bachelor of Science</option>
<option value="MBA" selected="selected">Master of
Business Administration</option>
</select>
<br / > <br>
<label for="studentid">Student ID</label>
66
Cont..
Cont..
68
What is Multimedia?
</video>
The HTML <audio> Element
<audio c o n t r o l s autoplay>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
</audio>
HTML Plug-ins
Plug-ins are computer programs that extend the standard
functionality of the browser.
To display maps
To verify a bank id
Cont..
The <object> element defines an
embedded object within an HTML
document.
<o b j e c t width="100%" h ei gh t="500px " data=
"s n ip p et . ht ml ">< / ob je ct>
The <embed> element can also be used to
include HTML in HTML:
<embed width="100%" he i g h t="500px" s r c ="s
n ip pe t .h t ml" >
Reading Assignment
HTML Graphics
• 2.2.10.1. HTML Canvas
• 2.2.10.2. HTML SVG
?