CH 2
CH 2
By Tesfahun
N.
Outline
❖ What is HTML
Basic HTML syntax
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
sacrificed
7
HTML page structure
HTML describes structure using two main
sections:
<head>
<body>
HTML Structure
HTML is included of “elements” and “tags”
• Begins with <html> and ends with </html>
definition (DTD)
It informs the web browser about the type and version
of HTML
10
HTML Tags
The <html> root element of an HTML page
Image Tags
<img src="logo.gif"/>
<body>
<a href="https://www.youtube.com/" title=
“youtube site">This is a link.</a>
<br />
<img src="logo.gif" />
<br />
<b>Bold</b> and <i>italic</i> text.
</body>
13
First HTML Page
test.html
<!DOCTYPE html>
<html>
<head>
<title>well came to WP</title>
</head>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html> 14
HTML Attributes
16
href Attribute
The <a> tag defines a hyperlink.
• Example
• <a href="https://www.google.com">Visit google</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
Id,
Style,
Class,
Title etc
20
The width and height Attributes
• Example
• <img src="img_girl.jpg" width="500" height="600">
The style Attribute
The style attribute is used to add styles to an
element, such as color, font, size, and more.
• Example
• <p style="color:red;">This is a red paragraph.</p>
The lang Attribute
Adding the lang attribute inside the <html> tag, to declare
the language of the Web page.
<!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 is my first paragraph</p>
<p>This is my second paragraph</p>
<meta>
<script>
<link>
<style>
26
Header
<!DOCTYPE HTML> HTML header
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<p>This is some text...</p>
</body>
</html> 27
<head> Section: <title> tag
Title should be placed between <head> and </head> tags
<head>
<title>here is the title section </title>
</head>
28
<head> Section: <meta>
Meta tags additionally describe the content contained
within the page
29
<head> Section: <script>
The <script> element is used to embed scripts into an
HTML document
Script are executed in the client's Web browser
VBScript
30
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= "text/javascript">
sayHello();
</script>
</body>
</html>
31
<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 { font-size: 12pt; line-height: 12pt; }
p:first-letter { font-size: 200%; }
span { text-transform: uppercase; }
</style>
</head>
<body>
<p>Styles demo.<br />
<span>Test uppercase</span>.
</p>
</body>
</html>
32
<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 is the Web page body -->
</body>
</html>
33
Comments: <!-- --> Tag
Comments can exist anywhere between the <html></html> tags
34
Text Formatting
Text formatting tags modify the text between the opening tag and the closing tag
• Ex. <b>Hello</b> makes “Hello” bold
35
Hyperlinks: <a> Tag
Link to a document called form.html on the same server in the
same directory:
<a href="form.html">Fill Our Form</a>
Link to a document called parent.html on the same server in
the parent directory:
<a href="../parent.html">Parent</a>
Link to a document called cat.html on the same server in the
subdirectory stuff:
<a href="stuff/cat.html">Catalog</a>
36
Hyperlinks: <a> Tag (2)
Link to an external Web site:
Always use a full URL, including "http://",
not just www.somesite.com
<a href="http://www.devbg.org"
target="_blank">BASD</a>
Link to an e-mail address:
<a href="mailto:[email protected]?subject=Bug+Report">
Please report bugs here (by e-mail only)</a>
37
Hyperlinks and Sections
Link to another location in the same document:
<a href="#section1">Go to
Introduction</a>
...
<h2 id="section1">Introduction</h2>
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 />
...the 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
Lecture II
…..
Loading
Ordered Lists: <ol> Tag
Create an Ordered List using <ol></ol>:
<ol type="1">
<li>Apple</li>
<li>Orange</li>
<li>Grapefruit</li>
</ol>
1. Apple i. Apple
2. Orange ii. Orange
3. Grapefruit a. Apple iii. Grapefruit
A. Apple b. Orange I. Apple
B. Orange c. Grapefruit II. Orange
C. Grapefruit III. Grapefru
it
43
Unordered Lists: <ul> Tag
Create an Unordered List using <ul></ul>:
<ul type="disk">
<li>Apple</li>
<li>Orange</li>
<li>Grapefruit</li>
</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>
<li>Grapefruit</li>
</ol>
<ul type="disc">
<li>Apple</li>
<li>Orange</li>
<li>Grapefruit</li>
</ul>
<dl>
<dt>HTML</dt>
<dd>A markup lang…</dd>
</dl> 46
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
• <div style="font-size:24px; color:red">
• Div section
• </div>
49
•
Cont..
The <span> Tag
Inline style element
in the document
span.html
<p>This one is <span style="color:red; font-
weight:bold">only a test</span>.</p>
<p>This one is another <span style="font-size:32px;
font-weight:bold">TEST</span>.</p>
51
HTML Tables
HTML Tables (2)
Tables represent tabular data
A table consists of one or several rows
Each row has one or more columns
• <td>First</td>
• <td>Second</td></tr>
• </table>
• <table cellspacing="0" cellpadding="15" bgcolor="cyan"
border="3px"> <tr><td>First</td>
• <td>Second</td></tr>
• </table>
56
Column and Row Span
• Table cells have two important attributes:
Colspan rowspan
colspan="1" colspan="1" rowspan="1"
rowspan="2"
58
HTML Forms
Forms are the primary method for gathering data
from site visitors
Create a form block with
<form></form>
The “method" attribute tells how the form
Example:
data should be sent – via GET or POST
request
<form name="myForm" method=“POST/GET"
action="path/to/some-script.php">
……
...
</form>
The "action" attribute tells where the
form data should be sent 59
Form Fields
Single-line text input fields:
<input type="text" name="FirstName"
value="This is a text field" />
Radio buttons:
<input type="radio" name="title"
value="M." />
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="city" value="Ruse" />
61
Other Form Controls
Dropdown menus:
<select name=“department">
<option value="Value 1"
selected="selected">cs</option>
<option value="Value 2">IS</option>
<option value="Value 3">IT</option>
</select>
Submit button:
<input type="submit" name="submitBtn"
value="Apply Now" />
62
Other Form Controls (2)
Reset button – brings the form to its initial state
<input type="reset" name="resetBtn"
value="Reset the form" />
Image button – acts like submit but image is
displayed and click coordinates are sent
<input type="image" src="submit.gif"
name="submitBtn" alt="Submit" />
63
Other Form Controls (3)
Password input – a text field which masks the entered
text with * signs
<input type="password" name="pass" />
65
HTML Forms – Example
66
form.html
HTML Forms – Example
<form method="post" action="apply-now.php">
<input name="subject" type="hidden" value="Class" />
<fieldset style="width:300px"><legend>Personal Details</legend>
<table>
<tr>
<td><label for="fname">First Name</label></td>
<td><input type="text" name="fname" id="fname" /></td>
</tr>
<tr>
<td><label for="lname">Last Name</label></td>
<td><input type="text" name="lname" id="lname" /></td>
67
</tr>
form.html (continued)
<tr>
<td><label for="degree">Degree</label></td>
<td><select name="degree" id="degree">
<option value="BA">cs</option>
<option value="BS">SE</option>
<option value="MBA"
selected="selected">IT</option>
</select></td>
</tr>
<tr>
<td>Student ID</td>
<td><input type="text" name="s" /></td>
</tr>
68
Cont..
<tr>
<td>Password</td>
<td><input type="Password" placeholder="Enter Password" name="s" /></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input name="gender" type="radio" id="gm" value="m" />
<label for="gm">Male</label>
<input name="gender" type="radio" id="gf" value="f" />
<label for="gf">Female</label></td>
</tr>
Cont.…
<tr>
<td></td>
<td><button type="submit">send</button>
</td>
</tr>
</fieldset>
</form>
What is Multimedia?
<video width="320" height="240" controls>
<source src=“m.mp4" type="video/mp4">
<source src=“m.ogg" type="video/ogg">
</video>
The HTML <audio> Element
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
</audio>
HTML <audio> Autoplay
<audio controls 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.
It was designed to embed plug-ins (like Java applets, PDF readers, and
Flash Players) in web pages, but can also be used to include HTML in
HTML:
<object width="100%" height="500px" data="snippet.html"></object>
<embed width="100%" height="500px" src="snippet.html">
Reading Assignment
HTML Graphics
• HTML Canvas
•HTML SVG
Thanks
?