Chap 2 PDF
Chap 2 PDF
Chap 2 PDF
HTML Basics
The World Wide Web is constructed from many millions of individual pages, and those pages
are, in general, written in Hypertext Markup Language, better known as HTML. The Hyper Text
Markup Language (HTML) is an application for marking up documents for inclusion in the
World Wide Web. We use it to mark up our text documents so that web browsers know how to
display them and todefine hypertext links within them to provide navigation within or between
them.HTML allows you to:
• Publish documents to the Internet in a platform independent format
• Create links to related works from your document
• Include graphics and multimedia data with your document
• Link to non-World Wide Web information resources on the Internet
HTML was originally intended to be used for encoding document structures. While there are
now many formatting and formatting-like tags, there are also numerous tags that apply to text
structures like headings, paragraphs and tables.
What is Markup?
To use HTML, you must understand the concept of markup:
• Markup is the act of inserting additional text into a document which is not usually visible
to the reader, and is not part of the content, but enhances the document in some way, such
as capturing document structure or adding hypertext capability
• Markup also refers to the additional text, also known as tags, which are inserted in the
document.
HTML Markup
HTML tags are used to markup the structure of a document, and embed basic formatting
information that the browser can use to decide how to display the content. HTML has two types
of markup: tags and character entities.
• Tags are constructed of brackets between which the tag is placed. Tags are placed around
segments of text, so there is usually a companion end tag which is identical to the start
tag except it includes a forward slash. Here are start and end tags for a title:
<TITLE>Introduction to HTML</TITLE>
• HTML also includes markup called character entities. These are used to include
international characters as well as characters usually included in tags as markup. Entities
1
BY Abdela A/2020
Chapter Two HTML Basic
start with an ampersand, followed by the entity name and end with a semicolon. For
example, nonbreaking space entity, “ ”
HTML Files
Creating an HTML file is pretty simple. You start it with a starting HTML tag, <html>, and end
it with a closing HTML tag, </html>. Everything in-between is the content of your file. The only
other requirement for an HTML file is that all HTML documents must have a filename extension
of .html or .htm. For example: sample.html
The browser looks at the filename extension and knows to interpret the file as HTML tags rather
than straight ascii text.
2
BY Abdela A/2020
Chapter Two HTML Basic
3
BY Abdela A/2020
Chapter Two HTML Basic
<head> - The container for page header information
<title> - The title of the page
<body> - The main body of the page
Remember that before an opening <html> tag, an XHTML document can contain the optional
XML declaration, and it should always contain a DOCTYPE declaration indicating which
version of XHTML it uses
HTML Paragraphs
Paragraphs are defined with the <p> tag.
Example
<p>This is a paragraph</p>
<p>This is another paragraph</p>
4
BY Abdela A/2020
Chapter Two HTML Basic
HTML Comment Tags
You can add comments to your HTML source by using the following syntax:
<!-- Write your comments here -->
Comments are not displayed by the browser, but they can help document your HTML.
Example
<!-- This is a comment -->
<p>This is a paragraph.</p>
<!-- Remember to add more information here -->
Adding Background Colors
There is nothing like a splash of color to add visual interest to a publication. We will change the
background color and text color for the entire sample.htm page.
Indenting Text
Generally, shorter lines of text look more friendly to the reader. Therefore, indenting the text
addsvisual appeal. An easy way of indenting paragraphs is with the <blockquote> tag.
Example
<blockquote>
At the end of your paragraph turn off the indention by typing:
</blockquote>
5
BY Abdela A/2020
Chapter Two HTML Basic
The URL points to the location where the image is stored. The browser displays the image where
the <img> tag occurs in the document. If you put an image tag between two paragraphs, the
browser shows the first paragraph, then the image, and then the second paragraph.
Example
<img src="image.jpg" alt="Servers.com" width="104" height="142">
HTML Attributes
• HTML elements can have attributes
• Attributes provide additional information about an element
• Attributes are always specified in the start tag
• Attributes come in name/value pairs like: name="value"
Example
HTML links are defined with the <a> tag. The link address is specified in the href attribute:
Example
<a href="/index.html">This is a link</a>
6
BY Abdela A/2020
Chapter Two HTML Basic
Note: The link address is specified in the href attribute.
7
BY Abdela A/2020
Chapter Two HTML Basic
8
BY Abdela A/2020
Chapter Two HTML Basic
• (tr stands for table row) A row is divided into data cells with the <td> tag. (td stands for
table data)
• A row can also be divided into headings with the <th> tag. (th stands for table heading)
• The <td> elements are the data containers in the table
•The <td> elements can contain all sorts of HTML elements like text, images, lists, other
tables, etc.
Example 1:
<table style="width:300px">
<tr>
<td>First name</td>
<td>Second name</td>
<td>Age</td>
</tr>
<tr>
<td>Lemma</td>
<td>Girma</td>
<td>94</td>
</tr>
</table>
Example 2
<table style="width:300px">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Points</th>
</tr>
<tr>
<td>Lemma</td>
<td>Girma</td>
<td>54</td>
</tr>
</tr>
</table>
9
BY Abdela A/2020
Chapter Two HTML Basic
HTML list
HTML Unordered Lists: An unordered list starts with the <ul> tag. Each list item starts
with the <li> tag. The list items are marked with bullets (typically small black circles).
<ul>
<li>Coffee</li>
<li>Milk</li>
</ul>
HTML Ordered Lists: An ordered list starts with the <ol> tag. Each list item starts with the
<li> tag. The list items are marked with numbers.
<ol>
<li>Coffee</li>
<li>Milk</li>
</ol>
How the HTML code above looks in a browser:
1. Coffee
2. Milk
TML Description Lists:A description list is a list of terms/names, with a description of each
term/name.
• The <dl> tag defines a description list
• The <dl> tag is used in conjunction with <dt> (defines terms/names) and
• <dd> (describes each term/name):
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
10
BY Abdela A/2020
Chapter Two HTML Basic
The tag that creates a link is simply “a” tag with an attribute. So far, we have not taken the time
to dissectwhat each code means, because most of them are obvious. The link tag breakdown as
follows:
• “a” This means Anchor
• “href=”http://www.aau.edu.et” This means Hypertext Reference. For remote sites, you
must type the entire web address.
• “Addis Ababa University” This is the title or description of the site or a link text.
• “</a>”: The ending anchor.
Example 2.
<a href=”home.htm”>Home</a>
This example shows how to link to an html file with in the same webpage.
“Home” :is the link text
“home.htm”: is the html file to open when the Home link is clicked.
Email Links
You created links in remote and internal the exercises above. Another kind of link is the email.
Theformat of an e-mail address is as follows:
11
BY Abdela A/2020
Chapter Two HTML Basic
<ahref="mailto:yourname@domain.com">…</a>
where:
<A The beginning anchor or link
HREF Refers to the place that will be linked
mailto: The special tag for linking to email
yourname@domain.com> Your email address
… Any text you want to display
</a> The end of the Anchor tag
Example
Please email us at: <a href=”mailto:ourmail@yahoo.com”>
Contact us</a>
HTML Forms
HTML forms are used to pass/ submit data from the client to a server. An HTML form can
contain input elements like text fields, checkboxes, radio-buttons, submit buttons and more. A
form can also contain select lists, textarea, fieldset, legend, and label elements, pull-down menus,
clickable images.
The <form> tag is used to create an HTML form:
<form>
.input elements
</form>
All of the form elements within a <form> tag comprise a single form. The browser sends all of
the values of these elements - blank, default, or user modified - when the user submits the form
to the server.
Browsers flow forms into the containing elements as if they were small embedded images. So
layout elements such as <p> and <br> need to be used.
Form Attributes
• action - gives the URL of the application that is to receive and process the forms data;
most of these are kept in cgi-bin or cgi-win; Common Gateway Interface binaries;
Example:
<form action="server.php" ...</form>
• enctype - the browser encodes the form's data before it is passed to the server. The server
may then decode the parameters or pass them still encoded to the application; standard
encoding format is Internet Media Type named "application/x-www-form-urlencoded";
only other type is "multipart/form-data"
12
BY Abdela A/2020
Chapter Two HTML Basic
• method - sets the HTTP method that the browser uses to send the form's data to the
server for processing; Either POST or GET;
Example: <form method=GET action="server.php" ...</form>
POST/ GET methods
Post
The browser sends the data in two steps:
• contacts the form processing server specified in the action attribute;
• sends the data to the server in a separate transmission;
On the server side POST-style applications are expected to read the parameters from a standard
location once they begin execution.
GET
Contacts the form-processing server and sends the form data in a single transmission step:
• the browser appends the data to the form's action URL, separated by the ? character
Some rules of thumb about which to use
• Send small forms with a few short fields via the GET method for better form
transmission performance;
• Some server operating systems limit the length of command line arguments that can be
passed to an application. Use the POST method;
• If security is an issue, choose POST because GET places the form parameters directly
in the application URL (easily captured by network sniffers); POST can take advantage
of encryption when transmitting the parameters as a separate transaction;
13
BY Abdela A/2020
Chapter Two HTML Basic
How the HTML code above looks in a browser:
First name:
Last name:
Note: The form itself is not visible. Also note that the default width of a text field is 20
characters.
Password Field
<input type="password"> defines a password field:
<form>
Password: <input type="password" name="pwd">
</form>
Note: The characters in a password field are masked (shown as asterisks or circles).
Multiple-Line Text Input Controls:
If you want to allow a visitor to your site to enter more than one line of text, you should create a
multiple-line text input control using the <textarea> element.
Radio Buttons
<input type="radio"> defines a radio button. Radio buttons let a user select ONLY ONE of a
limited number of choices:
<form>
<input type="radio" name="sex" value="male">Male<br>
<input type="radio" name="sex" value="female">Female
</form>
How the HTML code above looks in a browser:
Male
Female
14
BY Abdela A/2020
Chapter Two HTML Basic
Checkboxes
<input type="checkbox"> defines a checkbox. Checkboxes let a user select ZERO or MORE
options of a limited number of choices.
<form>
<input type="checkbox" name="vehicle" value="Bike">I have a bike<br>
<input type="checkbox" name="vehicle" value="Car">I have a car
</form>
How the HTML code above looks in a browser:
I have a bike
I have a car
Submit Button
<input type="submit"> defines a submit button.
A submit button is used to send form data to a server. The data is sent to the page specified in the
form's action attribute. The file defined in the action attribute usually does something with the
received input:
<form name="input" action=" action.php" method="get">
Username: <input type="text" name="user">
<input type="submit" value="Submit">
</form>
How the HTML code above looks in a browser:
Submit
Username:
If you type some characters in the text field above, and click the "Submit" button, the browser
will send your input to a page called "action.php". The page will show you the received input.
Drop-down menu or list
A menu or list:
<select name="select">
<option value="red">red</option>
<option value="green">green</option>
<option value="BLUE">blue</option>
</select>
Additional arguments:
15
BY Abdela A/2020
Chapter Two HTML Basic
A complete example
If you would like to provide your web site visitors with a simple way to contact you from your
website, but really don't want to display your email address, this HTML form code may be what
you'relooking for.You can create a simple form, as displayed below, to enable your visitors to
send you comments,questions, product support requests, or whatever you'd like.
A complete example code for the above form showed in the picture is as follows
<HTML>
<BODY>
<FORM action="mailto:you@yourdomain.com" method="post" enctype="text/plain">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="4" WIDTH="90%">
<TR>
<TD width="30%"><DIV align="right"><B>Name:</B></DIV></TD>
<TD width="70%"><INPUT type="text" name="name" size="20"></TD>
</TR>
<TR>
<TD><DIV align="right"><B>Email:</B></DIV></TD>
<TD><INPUT type="text" name="email" size="20"></TD>
</TR>
<TR>
<TD align="right"><b>Comment:</b></td><td><LABEL>
<TEXTAREA name="textarea"></TEXTAREA>
</LABEL>
</TD>
</TD>
<TR>
16
BY Abdela A/2020
Chapter Two HTML Basic
<TD><DIV align="right"></DIV></TD>
<TD><INPUT type="submit" value="Submit" name =”send”></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
17
BY Abdela A/2020