Chapter Two_HTML-3
Chapter Two_HTML-3
HTML
1
Introduction
What is HTML?
• HTML is the standard markup language for creating Web
pages.
• HTML stands for Hyper Text Markup Language
• HTML describes the structure of Web pages using markup
• HTML elements are the building blocks of HTML pages
• HTML elements are represented by tags
• HTML tags label pieces of content such as "heading",
"paragraph", "table", and so on
• Browsers do not display the HTML tags, but use them to
render the content of the page
2
Introduction
A Simple HTML Document (Example)
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html>
3
Introduction
Example Explained
• The <!DOCTYPE html> declaration defines that this document is an
HTML5 document
• The <html> element is the root element of an HTML page
• The <head> element contains meta information about the HTML
page
• The <title> element specifies a title for the HTML page (which is
shown in the browser's title bar or in the page's tab)
• The <body> element defines the document's body, and is a
container for all the visible contents, such as headings, paragraphs,
images, hyperlinks, tables, lists, etc.
• The <h1> element defines a large heading
• The <p> element defines a paragraph
4
Introduction
What is an HTML Element?
• An HTML element is defined by a start tag, some content, and an
end tag:
<tagname>Content goes here... </tagname>
• The HTML element is everything from the start tag to the end tag:
<h1>My First Heading</h1>
<p>My first paragraph.</p>
9
Introduction
The <head> Section
• Contains information that doesn’t show directly on the
viewable page
• Starts after the <!doctype> declaration
• Begins with <head> and ends with </head>
• Contains mandatory single <title> tag
• Can contain some other tags, e.g.
– <meta>
– <script>
– <style>
– <!–- comments -->
10
<head> Section: <title> tag
• Title should be placed between <head> and
</head> tags
<title>Telerik Academy–Winter Season
2009/2010 </title>
<meta charset="utf-8">
12
<head> Section: <script>
• The <script> element is used to embed
scripts into an HTML document
– Script are executed in the client's Web browser
– Scripts can live in the <head> and in the <body>
sections
• Supported client-side scripting languages:
– JavaScript (it is not Java!)
– VBScript
– JScript
13
The <script> Tag – Example
<!DOCTYPE HTML> scripts-example.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> 14
<head> Section: <style>
• The <style> element embeds formatting
information (CSS styles) into an HTML page
<html> style-example.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> 15
Comments: <!-- --> Tag
• Comments can exist anywhere between the
<html></html> tags
• Comments start with <!-- and end with -->
<!–- AMU Logo (a JPG file) -->
<img src="logo.jpg" alt=“amu Logo">
<!–- Hyperlink to the web site -->
<a href="http://www.amu.edu.et/">Arba
Minch University</a>
<!–- Show the news table -->
<table class="newstable">
...
16
<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>
17
Introduction
The <!DOCTYPE> Declaration
• The <!DOCTYPE> declaration represents the
document type, and helps browsers to display web
pages correctly.
• It must only appear once, at the top of the page
(before any HTML tags).
• The <!DOCTYPE> declaration is not case sensitive.
• The <!DOCTYPE> declaration for HTML5 is:
<!DOCTYPE html>
18
HTML Attributes
• Attributes provide additional information about
HTML elements.
• All HTML elements can have attributes
• Attributes provide additional Information about an
element.
• Attributes are always specified in the start tag
• Attributes usually come in name/value pairs
like: name="value“
• Example: <p style=“color:Yellow”;>
<body bgcolor=“blue”>
19
HTML Attributes
The href Attribute
• HTML links are defined with the <a> tag. The link address is
specified in the href attribute:
• Example
<a href="https://www.amu.edu.et">This is a link</a>
The src Attribute
• HTML images are defined with the <img> tag.
• The filename of the image source is specified in
the src attribute:
• Example
<img src=“amu_logo.jpg">
20
HTML Attributes
The width and height Attributes
• Images in HTML have a set of size attributes, which specifies the width and
height of the image:
• Example
<img src="img_girl.jpg" width="500" height="600">
• The image size is specified in pixels: width="500" means 500 pixels wide.
The title Attribute
• Here, a title attribute is added to the <p> element. The value of the title
attribute will be displayed as a tooltip when you mouse over the
paragraph:
• Example
<p title="I'm a tooltip">
This is a paragraph.
</p>
21
HTML Attributes
The lang Attribute
• The language of the document can be declared in the <html> tag.
• The language is declared with the lang attribute.
• Declaring a language is important for accessibility applications (screen readers)
and search engines:
<!DOCTYPE html>
<html lang="en-US">
<body>
...
</body>
</html>
• The first two letters specify the language (en). If there is a dialect, use two
more letters (US)
22
HTML Attributes
The HTML Style Attribute
• Setting the style of an HTML element, can be done with
the style attribute.
• The HTML style attribute has the following syntax:
<tagname style="property:value;">
• The property is a CSS property. The value is a CSS value.
Example:
– <body style="background-color:blue;">
– <h1 style="color:blue;">This is a heading</h1>
– <h1 style="font-family:arial;">This is a heading</h1>
– <h1 style="font-size:300%;">This is a heading</h1>
– <h1 style="text-align:center;">Centered Heading</h1>
23
HTML Attributes
We Suggest: Use Lowercase Attributes
• The HTML5 standard does not require lowercase
attribute names.
• The title attribute can be written with uppercase or
lowercase like title or TITLE.
• W3C recommends lowercase in HTML,
and demands lowercase for stricter document types
like XHTML.
24
HTML Attributes
• Below is an alphabetical list of some attributes often
used in HTML, which you will learn more about in this
tutorial:
Attribute Description
26
Formatting Text as Paragraphs …
38
HTML Tables …
Column and Row Span
• Table cells have two important attributes:
colspan rowspan
colspan="1" colspan="1" rowspan="2" rowspan="1"
colspan="2" rowspan="1"
40
Complete HTML Tables
• Table rows split into three semantic sections:
header, body and footer
– <thead> denotes table header and contains <th>
elements, instead of <td> elements
– <tbody> denotes collection of table rows that
contain the very data
– <tfoot> denotes table footer but comes BEFORE
the <tbody> tag
– <colgroup> and <col> define columns (most
often used to set column widths)
41
Complete HTML Table: Example
<table>
<colgroup>
columns
<col style="width:100px" /><col />
</colgroup> th
<thead>
header
<tr><th>Column 1</th><th>Column 2</th></tr>
</thead>
<tfoot>
footer
<tr><td>Footer 1</td><td>Footer 2</td></tr>
</tfoot>
<tbody>
Last comes the body (data)
<tr><td>Cell 1.1</td><td>Cell 1.2</td></tr>
<tr><td>Cell 2.1</td><td>Cell 2.2</td></tr>
</tbody>
</table>
42
Complete HTML Table:
By default, header text is
bold andExample
centered.(2)
<table> table-full.html
<colgroup>
<col style="width:200px" /><col />
</colgroup>
<thead>
<tr><th>Column 1</th><th>Column 2</th></tr>
</thead>
<tfoot>
<tr><td>Footer 1</td><td>Footer 2</td></tr>
</tfoot>
<tbody>
<tr><td>CellAlthough the footer is1.2</td></tr>
1.1</td><td>Cell
<tr><td>Cellbefore the data in the2.2</td></tr>
2.1</td><td>Cell
</tbody> code, it is displayed last
</table> 43
HTML Links - Hyperlinks
44
Linking Documents together
Anchor <a> used for navigation or linking html
documents together
Attributes:
href=“url”
target=“target” { _self, _blank }
name=“anchor name”
• Examples:
<a href=“home.htm”>Go to home</a>
Opens Google on the same tab or window, since _self is
default value of target attribute
<a href=“http://www.google.com” target=“_blank”>Google</a> 45
Linking Documents together
Navigation with named anchors
◦ named anchors
Used to navigate within named places in an html document
Format: <a name=“anchor_name”></a>
E.g. <a name=“top”></a>
◦ linking to named anchors
Format:
<a href=“#anchor_name”>link text</a> {on the same page}
<a href=“url#anchor_name”link text</a> {on a different page}
E.g.
<a href=“#top”>Back to Top</a> {assuming the example above}
<a href=“http://www.aau.edu.et/history.htm#establishment”> Establishment
of AAU</a>
46
Example-Linking documents
<html>
<head>
<title>Linking documents</title>
</head>
<body>
<!-- Anchor for navigating inside the page -->
<a name="top"></a>
<h2>Linking Documents</h2>
<!-- Link to a google website -->
<a href="http://www.google.com" target="_blank">Google</a>
<hr>
<img src="f:/entertainment/ch.jpg" width="600">
<hr>
<!-- Link to the top anchor -->
<a href="#top">Back to top</a>
</body>
</html>
47
HTML <marquee> Tag
• The <marquee> is a non-standard HTML tag which was
used to create a scrolling text or an image. It was used to
make the text/image scroll horizontally across or
vertically down the web page.
• The <marquee> element is a non-standard HTML
element. If you use this element, your pages or apps
may be broken.
Syntax: <marquee> content </marquee>
• The <marquee> element comes in pairs. It means that
the tag has opening (<marquee>) and closing
(</marquee>) elements.
48
HTML <marquee> Tag
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<marquee>This is a text to be scroll</marquee>
</body>
</html>
49
HTML <marquee> Tag
Attribute Value Description
rgb(x,x,x) , #xxxxxx
bgcolor Is used to give a background color.
colorname
50
Block and Inline Elements
• Block elements: add a line break before and after
them
– <div> is a block element
– Other block elements are <table>, <hr>, headings,
lists, <p> and etc.
• Inline elements don’t break the text before and
after them
– <span> is an inline element
– Other inline elements are <a>, <b>, <u>, <i>,
<input>, <button>, etc.
51
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 data should be sent – via
• Example: GET or POST request
• Password input – a text field which masks the entered text with *
signs
<input type="password" name="pass" />
54
HTML Forms …
Image button – acts like submit but image is
displayed and click coordinates are sent
<input type="image" name="imagebutton"
src="11.jpg" height="50" width="50"/>
• File input – a field used for uploading files
<input type="file" name="photo" />
• Checkboxes:
<input type="checkbox" name="fruit"
value="apple”/>
• 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=“Sex"
value=“Male" />
<input type="radio" name=“Sex" value=“Female"
/> 56
HTML Forms …
• Dropdown menus:
<select name=“Degree Type">
<option value="Value 1"
selected="selected">MA</option>
<option value="Value 2">MSc</option>
<option value="Value 3">BED</option>
</select>
• Multiple select field – displays the list of items in
multiple lines, instead of one.
<select name="products" multiple="multiple">
<option value="Value 1"
selected="selected">keyboard</option>
<option value="Value 2">mouse</option>
<option value="Value 3">speakers</option>
</select> 57
HTML Forms …
Label
• 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" />
62
HTML 5 form
• Use auto complete input elements that help users re-
enter text that they’ve previously entered in a form.
• Use self-validating input elements.
• Specify temporary placeholder text in various input
elements
• Specify an input element in a form as the one that
should receive the focus by default.
• Use a data list to specify a list of values that can be
entered in an input element and to auto complete
entries as the user types.
63
HTML5: New form elements
64
HTML Frames
• Frames provide a way to show multiple HTML
documents in a single Web page
• The page can be split into separate views (frames)
horizontally and vertically
• Frames were popular in the early ages of HTML
development, but now their usage is rejected
• Frames are not supported by all user agents
(browsers, search engines, etc.)
– A <noframes> element is used to provide content for
non-compatible agents.
65
HTML Frames …
<html>
<head><title>Frames Example</title></head>
<frameset cols=“*,*,*">
<frame src="left.html" />
<frame src="middle.html" />
<frame src="right.html" />
</frameset>
</html>
67
HTML5-Page Structure
HTML5 Semantic Elements
• <header> - Defines a header for a document or a section
• <nav> - Defines a set of navigation links
• <section> - Defines a section in a document
• <article> - Defines an independent, self-contained
content
• <aside> - Defines content aside from the content (like a
sidebar)
• <footer> - Defines a footer for a document or a section
68
HTML5-Page Structure …
HTML5 Semantic Elements
• <details> - Defines
additional details that
the user can open and
close on demand
• <summary> - Defines a
heading for the
<details> element
69
HTML5-Page Structure …
70