Lesson 3 (E)
Lesson 3 (E)
Lesson 3 (E)
Learning Outcomes
After completion of this lesson, the learner will be able to perform web page creation and basic
formatting using HTML elements.
• Create web pages by using HTML
• Write HTML codes with basic formatting elements
• Describe special usage of each basic element
• Describe HTML/XHTML design standards with respect to W3C
• Describe main differences of HTML and XHTML
Lesson Outline:
• How to create web page with a text editor?
• Use of basic HTML page structure
html, head, title, body, and text elements
• Common html elements and design formatting elements
Headings, paragraph, breaks, horizontal rulers, bold, italic, delete, etc.
• Web element attributes and their usage with examples
Images, text colors, background colors, videos, alignments etc.
• Hyperlinks and referential web structures
Internal links and external links and relative paths
3.1 How to create web page with a text editor?
As mentioned in previous lesson there are so many HTML editors. For a beginner the best way
is to use a TXT editor. Following are the steps to make a simple HTML file using notepad. Follow
the steps and try by yourself.
Go to Start> All Programs> Accessories> Notepad or simply right click on your desktop>
New> Text Document.
Type the HTML Code.
Save as yourtitle.html
Double click on your html file to view in the web browser.
Figure 1: Step 1
Figure 2: Step 2
Figure 3: Step 3
File will be select a web browser to open with. So it will looks like this. Final step is to double
click on this html file so it will open from a web browser. It will looks like the following image.
EXAMPLE:
<html>
<head>
<title>Web Authoring</title>
</head>
<body>
<p>HTML is easy!!</p>
<h1>This line using h1</h1>
<h2>This line using h2</h2>
<h3>This line using h3</h3>
<h4>This line using h4</h4>
<h5>This line using h5</h5>
<h6>This line using h6</h6>
</body>
</html>
Activity 3.1: - Tryout the code above and see the difference of each header.
EXAMPLE:
<html>
<head>
<title>Web Authoring</title>
</head>
<body>
<p><font face=“Arial, Tahoma, Lucida Sans”> This is Arial, Tahoma, and Lucida
sans font </font></p>
<p><font face=“Times New Roman, Times, serif”> This is Times New Roman,
Times, serif font </font></p>
</body>
</html>
Activity 3.2: - Implement the above code and observe the output of the code.
Activity 3.3: Design the above text by using the code given on figure 6.1. Try to change the font
type and color together according to your preference.
Copy the web page created in activity 3.1 and modify it to display six (6) headers titles in six
different colours. Hint: you may use: <h…> <font ….> …… </font></h…>
Further to the above, please visit the following link and apply changes to the code where ever
necessary to obtain font types, size and colors.
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_font
c. Set line break
There are several ways to keep breaks on the content we write on web pages. <p></p> tags is
used to enclose a paragraphs on webpages. The content which are to be in the paragraph
should be in between the start and end tags. New paragraph will get a break between 1st and
2nd paragraph. To have a break without paragraphs <br> or </br> tags can be used (also <br/>).
<p>……..</p> to produce a new paragraph
<br> … </br> to produce a new line break
The following example in figure 7 shows the application of <p> and <br> tags.
EXAMPLE
<html>
<head>
<title>Web Authoring</title>
</head>
<body>
<p>Welcome to HTML!</p>
</body>
</html>
The <p> … </p> or <p/> tag separate the text content into paragraphs. Implement the above
example for your self-assessment.
d. Set various text formats
There are tags to manipulate the shapes and forms of the text. Few of those tags are described
below.
Tags Description
<b>...</b> ----------------------------------Bold
<i>...</i> ------------------------------------Italic
<u>...</u> ---------------------------------Underline
<sub>...</sub> ---------------------------Subscript
<sup>...</sup> ---------------------------Superscript
If a phrase or sentence were written in-between these tags those will have the shapes or forms
according to the tags behavior. The following in figure 8 shows the applications of above tags.
EXAMPLE
<html>
<head>
<title>Web Authoring</title>
</head>
<body>
<p>Welcome to HTML!</p>
<p>
<b>Bold</b>
<i>Italic</i>
<u>Underline</u>
<sub>Subscript</sub>
<sup>Superscript</sup>
</p>
</body>
</html>
<head>
<title>Web Authoring</title>
</head>
<body>
<p>Welcome to HTML!</p>
</body>
</html>
f. Comments
Comment tags are used to insert comments in the HTML source code. These comments will
only be seen on the editor. Comments are not displayed by the browser, but they can help
document your HTML source code. You can add comments to your HTML source by using the
following syntax.
Syntax Example:
<!-- This is a comment -->
With comments you can place notifications and reminders in your HTML. And also comments
will be important when debugging the HTML code.
g. Text alignment
Alignment of text in a document is very important. The followings are the main alignment
attribute values which are used in HTML.
Syntax example:
<p align=”left”> Left alignment.
<p align=”right”> Right alignment.
<p align=”center”> Centre alignment.
Figure 10 shows the code and the output to illustrate the application of align attribute. Apply
the code and observe the output.
Example
<html>
<head>
<title>Web Authoring</title>
</head>
<body>
<p>Welcome to HTML!</p>
<p align="left">This is a left alignment paragraph</p>
<p align="center">This is a center alignment paragraph</p>
<p align="right">This is a right alignment paragraph</p>
</body>
</html>
Activity 3.4
Examine the use of img tag with its’ attributes in the following link and design a web page by
inserting an image in between two text paragraphs (above and below). Align the image to the
center of the page horizontally. Create image caption under the image. Use “alt” attribute to
insert display message about image when move the mouse.
Include an image from outside source in the internet using src attribute at the end of the page.
Link: https://www.w3schools.com/tags/tag_img.asp
3.2.4 Add video to webpage
A video file can be inserted to html using <video> tag in the same way which we used to add an
image but there are common attributes as well as attributes which only compatible with videos.
The size and the type of the video should be given at the first place. The attributes and their
behaviors are as follows.
autoplay - sets whether the file will run automatically after the page is loaded. Can have
hidden - sets whether the buttons are hidden or not. Can have the true or false value.
loop- sets whether the file will be replayed after it is finished. Can have the true or false
value.
playcount - this establishes how many times the file will be replayed. For example
playcount="2" means it will be replayed two times and after it will stop
<html>
<head>
<title>Web Authoring</title>
</head>
<body>
<p>Welcome to HTML!</p>
<video width="320" height="240" controls>
<source
src="C:\Users\Rana\Desktop\HTML\2.MP4"
type="video/mp4" >
</video></body>
</html>
Figure 12: Displaying a video on a page
The format of the video is also important. It depends in the web browser you use to display the
webpage. There are few well known formats. The most used are .mpeg and .swf, because of the
compact format. Figure 12 shows an example on attaching a video source in the given machine
by using src attribute of source child tag.
Activity 3.5
Refer the attributes and features available for the video tag described in the following link and
use the “try yourself” activities given on the links.
Links: https://www.w3schools.com/tags/tag_video.asp
https://www.w3schools.com/tags/att_video_poster.asp
Design a web page by inserting a video which is on the internet source. Further, add a poster
image as initial image for the video display. Set the size of the video as 480 x 320.
3.2.5 Hyperlinks
Links are found in nearly all web pages. Links allow users to click their way from page to page.
HTML links are hyperlinks, the information organization and the power of the web relies on
hyperlinks. Perhaps the most important HTML element is the hyperlink, or ANCHOR tag. You
can click on a link and jump to another document. When you move the mouse over a link, the
mouse arrow will turn into a little hand (you may define it). A link does not have to be text. It
can be an image or any other HTML element (object).
Tag Syntax: <a href="URL">…</a> where URL is the Web address of the page to be displayed
when the user clicks on the link
if the page is accessed over the Web, must start with http://
if not, the browser will assume it is a name of a local file (local path)
Target attribute specify the place of new link to be display (self-overwrite or new page).
Tag : <a href="URL" target="_blank">…</a> causes the page to be loaded in a new window
Note: A link does not have to be text. It can be an image or any other HTML element.
The following example in figure 13 gives a code and output of a web page with hyperlinks.
Example
<html> <!—Hyperlink Demo -->
<head>
<title>Hyperlinks</title>
</head>
<body> <p> <a href="https://www.mrt.ac.lk/web/itfac/education/undergraduate/bachelor-
it"> BIT</a> <br>
<a href="pageOne.html" target="_blank"> Open page one in a new window</a>
</p>
</body>
</html>
Note: When you click BIT link in the page, it will redirect to the web address given in the code. If
you click the other link, it will open a new blanked tab in the browser with the title of pageone
on it. If there was a HTML file call pageOne.html on the same web page file location, it will be
displayed.
Activity 3.5
Refer and perform all the “try yourself” activities given in the following link.
https://www.w3schools.com/tags/tag_a.asp.
Create a web page with hyperlinks given to images. Examine on linking to sections in the same
page (links works within the same page).
3.3 HTML Forms
Web forms play a major role in web applications. Primarily the user interaction on web and
inputs for the web is taken through form elements. There are various Graphical User Interface
(GUI) widgets bundled under the form element as child elements. Followings are some of the
prominent features of web forms:
HTML forms are used to create (rather primitive) GUIs on Web pages
Usually the purpose is to ask the user for information (Inputs)
The information is then sent back to the server or process in the same script
Forms are created using the tags <form> … </form> pair
Form elements (child) include: buttons, checkboxes, text fields, radio buttons, drop-
down menus, etc…
A form usually contains a “Submit” button to send the information in the form elements
to the server or a specific program
The parameters of the form starting tag define how to send the information
ACTION (attribute): Takes URL where the data will be sent.
METHOD: can be set to POST or GET (POST and GET features have different capabilities)
POST – The default method. User data is placed in the form collection of the request
object to be passed to the server.
GET – User data is passed to the server by adding it to the end of the URL address. The
data is sent as an encoded stream.
Code Element
<OPTION SELECTED>one
</SELECT>
Activity 3.6
Tryout the following HTML code and understand the behavior of each HTML form element.
<HTML>
<BODY>
<h1 ALIGN=CENTER><FONT SIZE=+2>USER INFORMATION FORM</FONT></h1>
<FORM ACTION="/Scripts/simple.pl" METHOD="post" >
User Name:<INPUT TYPE="text" NAME ="uname" SIZE=30>
<BR>
Service Type:<SELECT NAME="service">
<OPTION>CAS</OPTION>
<OPTION>CDRS</OPTION>
<OPTION>COPSAT</OPTION>
<OPTION>DDS</OPTION>
<OPTION>FDSS</OPTION>
<OPTION>ISS</OPTION>
<OPTION>OSS</OPTION>
<OPTION>SAS</OPTION>
<OPTION>DA</OPTION>
</SELECT>
<BR>
<H4><NOBR>SUBJECT AREA:</H4>
<INPUT TYPE="checkbox" NAME="agriculture" >Agriculture
<INPUT TYPE="checkbox" NAME="biology" >Biology
<INPUT TYPE="checkbox" NAME="biomedicine" >Biomedicine
<INPUT TYPE="checkbox" NAME="chemistry" >Chemistry
<BR>
<BR>
<INPUT TYPE="radio" NAME="database">AGRIS
<INPUT TYPE="radio" NAME="database">AHEAD
<INPUT TYPE="radio" NAME="database">BIOSIS
<INPUT TYPE="radio" NAME="database">CAB
<BR>
<BR>
Date Entered:<INPUT TYPE="text" NAME ="entrydate"
SIZE=10">(dd/mm/yyyy)
<BR>
<BR>
<CENTER>
<INPUT TYPE= "submit" VALUE="Submit Form">
<INPUT TYPE= "reset" VALUE="Clear Form">
<CENTER>
</FORM>
</BODY>
</HTML>
Refer the information given in the following link and perform all the activities given as “Try
yourself”: https://www.w3schools.com/tags/tag_form.asp
HTML was the first accessible way that data could be interactively processed
Linking: Data is linked in HTML, letting one piece carry you to another.
Simplicity: HTML is simple, making it easy to learn
Portability: HTML is interpreted by the browsers, making it portable, especially in
distributed environment.
Not a Strict language
Easy to do the display formatting
Disadvantages of HTML:
3.5 XHTML
So far we have looked at pure HTML where it is based on the SGML standard of markup
languages.
SGML has now been largely replaced by XML (eXtensible Markup Language)
XML is simpler and stricter than SGML more suitable for “lightweight” processing in
Web applications
XHTML is an eXtensible and XML-compatible version of HTML 4
3.5.3 XHTML
Case sensitive
All elements must have start tags and end tags <p>Hello</p>
Empty elements contain their own end tag <br />
Attribute values must be enclosed in quotation marks