L2 HTML
L2 HTML
HTML
1
HTML
The head is used for text and tags that do not show directly on
the page.
The body is used for text and tags that are shown directly on the 3
page.
BASIC STRUCTURE OF A WEB PAGE
First and last tags
The HEAD section
must come before the BODY section
contains generic information about the document
PAGE STRUCTURE
<html>
<head>
<!-- This section is for the title and
technical
info of the page. -->
</head>
<body>
<!-- This section is for all that you want to
show on the page. -->
</body> 5
</html>
HTML TAGS
HTML tags are keywords surrounded by angle brackets < and >
start tag < > and end tag </ >
HTML tags normally come in pairs like <b> and </b>
The browser does not display the HTML tags, but uses the tags to
interpret the content of the page.
6
HTML TAGS
Open/Empty tag
• Do not have closing tags.
• Empty elements must also be closed .
e.g.:
An image: <img src="image.gif" />
A break: <br /> 7
<html>…</html>
<head>…</head> (Header)
Not all browsers require this tag. Contains information about the document
<title>…</title>
The text contained within these tags appears in your browser’s title ba 8
BASIC TAGS
<body>…</body>
Required. All of the information is contained between these tags.
<p>…</p> (Paragraph)
Used to create a new paragraph (inserts a new line and carriage return on your
page). The </p> Closing tag is optional. It is required when using
attributes with the <p> tag
9
HTML ELEMENTS
An HTML element is everything from the start tag to the end
tag.
<p>This is a paragraph</p>
</html>
HTML ATTRIBUTES
–Attributes
Only placed in the opening tag (not in the closing tag)
Use one or multiple attributes in a single tag separated by spaces
–Values
Text or numeric to further describe attributes
Some values are case-sensitive
Values should be enclosed in straight quotes ( ""), not curly ones ( “ ” ) 13
ATTRIBUTE EXAMPLE
HTML links are defined with the <a> tag. The link address
is specified in the href attribute:
Example
<body>
<a href="http://www.w3schools.com">
This is a link</a>
</body> 14
COMMENTS
Comments are delimited by <!-- and -->
</body>
<!DOCTYPE>
<!DOCTYPE html PUBLIC "-//w3c/dtd html 4.0 final//en">
The <!DOCTYPE> element should be used as the first line of all HTML
documents.
Validation programs might use this construct when determining the
correctness of an HTML document.
The DOCTYPE declaration defines the document type.
The "html" refers to the <html> root tag in the document.
PUBLIC points to the document type definition that is recorded with the
International Standards Organization. 16
HEADINGS
Six levels of importance <h1>...<h6>
Use headings to divide document into sections
17
EXERCISE 2
18
EXERCISE 2 : OUTPUT
19
HTML FORMATTING
HTML uses tags like <b> and <i> for formatting output, like bold or
italic text.
20
FORMATTING EXAMPLE
21
HTML STYLE ATTRIBUTE
22
FONT, COLOR AND SIZE
The font-family, color, and font-size properties defines the font, color, and size of
the text in an element:
<font> attributes
face - name of font (must be installed)
– "arial", "times", "verdana", "helvetica"
size - absolute size (1-7), or relative to previous text
– "2", "5", "7", "+1", "-2"...
color - hexadecimal RGB, or a named color
– "3399dd", "blue", "red"
23
24
BACKGROUND
Color
• Add a bgcolor property to the body tag
<body bgcolor=“#FF0000”>
Image
• Add a background property to the body tag
<body background=“flower.gif”> 25
SUMMARY OF BASIC TEXT FORMATTING
Font Styles and Sizes (can be nested)
<b>..</b> - Sets bold text.
<big>..</big> - Sets larger than normal text.
<em>..</em> - Sets text in italics and denotes emphasis.
<i>..</i> - Sets text in italics.
<small>..</small> - Makes text smaller than normal.
<strike>..</strike> - Draws a line through the text as a "strikeout".
<strong>..</strong> - Same as bold but denotes strong emphasis.
<sup>..</sup> -Superscript
<sub>..</sub> -Subscript
26
<u>..</u> - Underlined text.
EXERCISE 3: Create the following web-page
27
You can refer to https://www.w3schools.com/html/
ANSWER
28
FORMATTING
WIDTH:
Used to control the width of items like horizontal rules. (Specified in either
pixels or percentage %)
ALIGN:
Allows you to control which way to align text and objects using values of
29
30
EXERCISE 4 : OUTPUT
31
LIST TAGS
<li>…</li> (List Item)
Each item in the list must be preceded by this <li> tag
numbering).
TYPE ATTRIBUTE
33
TYPE ATTRIBUTE
34
EXERCISE 5: LISTS
35
Output
36
HYPERLINKS
There are 4 places you might want to link to:
1) Another web page in same folder you are linking
FROM.
2) Another web page in a different folder. The folder can
be beside, above or below the one you are linking from.
3) Another web page on a different server (another
website)
4) A specific location on the current web page
37
CREATING HYPERLINKS
Links are defined by the <a> Anchor tag and consist of two main parts:
the target source specified by the HREF attribute and
the actual document needed to create the "hotspot“.
<a>…</a> (Anchor)
This tag tells the browser that you will be linking to another page.
The Hypertext Reference or href attribute accompanies the anchor tag.
link</a>
Exercise 6: Referencing a location on same page
39
Exercise 6: Referencing a location on same page
40
TAGS FOR TABLES
<table>…</table>
Defines the table structure
<tr>…</tr> (Table Row)
Defines a row in the table
<td>…</td> (Table Data)
Creates a cell for the table
<th>…</th> (Table Heading)
Creates one or more headings (Usually appears centered and bold in
most browsers)
<caption>…</caption> 41
Creates a title for a table. (By default, this title appears above the
<TABLE> ATTRIBUTES
BGCOLOR
Creates a background color
BORDER
Creates a border around a table
BORDERCOLOR
Adds a color to the border
COLSPAN
Makes a row cross multiple columns
42
ROWSPAN
EXERCISE 7 - TABLES
43
SECTIONING THE PAGE
44
A. DIV TAG
<div>…</div>
Used to align paragraphs or blocks
of content in relation to the browser
window.
e.g <div align= "center">…</div>
45
NESTED DIV
46
FORMS
47
FORMS - DESIGN CONSIDERATIONS
Make the form easy to fill out.
It should be intuitive – should not require hard thinking to
figure out what to do.
Use selection pick lists and check boxes whenever possible.
Avoid asking for text that requires more than one word unless
necessary.
Group related information together. 48
FORMS
o
FORMS - TAGS
1. <form>…</form>
Starts and ends a form block.
The Action Attribute
The action attribute defines the action to be performed when the form is submitted.
Normally, the form data is sent to a web page on the server when the user clicks on the
submit button.
In the example above, the form data is sent to a page on the server called
"/action_page.php". This page contains a server-side script that handles the form data:
51
<form action="/action_page.php">
FORMS - TAGS
<input / >
Provides a place for input of any kind (input objects).
Can be a field for data or a button to click.
54
ATTRIBUTES
TYPE
Use with the INPUT tag to tell the browser what kind of input to process.
<input type="button|submit|reset">
Reset type is a button to clear the inputs.
Submit: A button to submit form element texts.
VALUE
The VALUE is what is the text on the button itself.
55
Use with the INPUT tag to provide a value to the input object.
ATTRIBUTES
NAME
Assigns a name to an input object. Should be unique for each
SIZE
Use with the <input /> tag to create a size (in length) for the input
object
56
OTHER TAGS
<select>…</select> (ComboBox)
Creates a selection list for a user to pick from
<option>… </option>
Creates an option in the SELECT list
57
ATTRIBUTES
MAXLENGTH
Use with a text field to limit the number of characters a
user can key in.
58
EXERCISE 8 - FORMS
59
PRACTICE QUESTION: CREATE THE FOLLOWING
FORM.
60
QUESTION 2: WRITE HTML CODE THAT DISPLAYS THE
FOLLOWING HOTEL ONLINE APPLICATION FORM: (10)
61
OTHER TAGS
OTHER TAGS
62
OTHER TAGS
OTHER TAGS
63
OTHER TAGS
OTHER TAGS
64
OTHER TAGS
OTHER TAGS
65
OTHER TAGS
OTHER TAGS
66
OTHER TAGS
OTHER TAGS
67